# HG changeset patch # User Rik # Date 1424134305 28800 # Node ID 5f2c0ca0ef517771fcc8efb727045021c4f088e8 # Parent abc158e7122ea4e727a8cbefd3b5068d2b9507fe Ensure that numbers passed to integer *printf format codes are integers (bug #44245). * num2str.m, validateattributes.m, inputname.m, stemleaf.m, print.m, __ghostscript__.m, __gnuplot_print__.m, __go_draw_axes__.m, __go_draw_figure__.m, bicg.m, qmr.m, mat2str.m, validatestring.m, assert.m: Ensure that numbers passed to integer *printf format codes are integers. diff --git a/scripts/general/num2str.m b/scripts/general/num2str.m --- a/scripts/general/num2str.m +++ b/scripts/general/num2str.m @@ -83,7 +83,7 @@ if (nargin == 2) if (ischar (arg)) fmt = arg; - elseif (isnumeric (arg) && isscalar (arg) && arg >= 0) + elseif (isnumeric (arg) && isscalar (arg) && arg >= 0 && arg == fix (arg)) fmt = sprintf ("%%%d.%dg", arg+7, arg); else error ("num2str: PRECISION must be a scalar integer >= 0"); @@ -122,7 +122,7 @@ if (nargin == 2) if (ischar (arg)) fmt = [arg "%-+" arg(2:end) "i"]; - elseif (isnumeric (arg) && isscalar (arg) && arg >= 0) + elseif (isnumeric (arg) && isscalar (arg) && arg >= 0 && arg == fix (arg)) fmt = sprintf ("%%%d.%dg%%-+%d.%dgi", arg+7, arg, arg+7, arg); else error ("num2str: PRECISION must be a scalar integer >= 0"); diff --git a/scripts/general/validateattributes.m b/scripts/general/validateattributes.m --- a/scripts/general/validateattributes.m +++ b/scripts/general/validateattributes.m @@ -327,7 +327,7 @@ endfunction function retval = valid_arg_idx (arg) - retval = isnumeric (arg) && isscalar (arg) && arg > 0 && ceil (arg) == arg; + retval = isnumeric (arg) && isscalar (arg) && arg > 0 && arg == fix (arg); endfunction function cls = replace_cl_group (cls, name, group) diff --git a/scripts/miscellaneous/inputname.m b/scripts/miscellaneous/inputname.m --- a/scripts/miscellaneous/inputname.m +++ b/scripts/miscellaneous/inputname.m @@ -35,7 +35,7 @@ print_usage (); endif - s = evalin ("caller", sprintf ("__varval__ (\".argn.\"){%d};", n)); + s = evalin ("caller", sprintf ("__varval__ (\".argn.\"){%d};", fix (n))); ## For compatibility with Matlab, ## return empty string if argument name is not a valid identifier. if (! isvarname (s)) diff --git a/scripts/plot/draw/stemleaf.m b/scripts/plot/draw/stemleaf.m --- a/scripts/plot/draw/stemleaf.m +++ b/scripts/plot/draw/stemleaf.m @@ -185,7 +185,7 @@ hl = xs(hlidx); # lower hinge hu = xs(huidx); # upper hinge h_spread = hu - hl; # h_spread: difference between hinges - step = fix(1.5*h_spread); # step: 1.5 * h_spread + step = fix (1.5*h_spread); # step: 1.5 * h_spread i_fence_l = hl - step; # inner fences: outside hinges + step o_fence_l = hl - 2*step; # outer fences: outside hinges + 2*step i_fence_h = hu + step; diff --git a/scripts/plot/util/print.m b/scripts/plot/util/print.m --- a/scripts/plot/util/print.m +++ b/scripts/plot/util/print.m @@ -542,7 +542,7 @@ opts.preview); endswitch if (! isempty (opts.ghostscript.resolution)) - cmd = sprintf ("%s --dpi %d", cmd, opts.ghostscript.resolution); + cmd = sprintf ("%s --dpi %d", cmd, fix (opts.ghostscript.resolution)); endif else cmd = ""; @@ -661,7 +661,7 @@ graphicsfile = strcat (opts.name, "-inc.eps"); endswitch papersize = sprintf ("\\usepackage[papersize={%.2fbp,%.2fbp},text={%.2fbp,%.2fbp}]{geometry}", - opts.canvas_size, opts.canvas_size); + fix (opts.canvas_size), fix (opts.canvas_size)); prepend = {"\\documentclass{minimal}"; packages; papersize; diff --git a/scripts/plot/util/private/__ghostscript__.m b/scripts/plot/util/private/__ghostscript__.m --- a/scripts/plot/util/private/__ghostscript__.m +++ b/scripts/plot/util/private/__ghostscript__.m @@ -69,15 +69,15 @@ gs_opts = sprintf ("-dQUIET -dNOPAUSE -dBATCH -dSAFER -sDEVICE=%s", opts.device); if (! isempty (opts.level) && ismember (opts.level, [1, 2, 3])) - gs_opts = sprintf ("%s -dLanguageLevel=%d", gs_opts, round (opts.level)); + gs_opts = sprintf ("%s -dLanguageLevel=%d", gs_opts, opts.level); endif if (opts.antialiasing && isempty (strfind (opts.device, "write"))) ## Apply anti-aliasing to all bitmap formats/devices gs_opts = sprintf ("%s -dTextAlphaBits=%d -dGraphicsAlphaBits=%d", - gs_opts, opts.antialiasing_textalphabits, - opts.antialiasing_graphicsalphabits); - gs_opts = sprintf ("%s -r%dx%d", gs_opts, [1, 1] * opts.resolution); + gs_opts, fix (opts.antialiasing_textalphabits), + fix (opts.antialiasing_graphicsalphabits)); + gs_opts = sprintf ("%s -r%dx%d", gs_opts, fix ([1, 1] * opts.resolution)); elseif (any (strcmp (opts.device, {"pswrite", "ps2write", "pdfwrite"}))) gs_opts = sprintf ("%s -dEmbedAllFonts=true", gs_opts); if (strcmp (opts.device, "pdfwrite")) @@ -95,7 +95,7 @@ gs_opts = sprintf ("%s -sPAPERSIZE=%s", gs_opts, opts.papersize); elseif (isnumeric (opts.papersize) && numel (opts.papersize) == 2) gs_opts = sprintf ("%s -dDEVICEWIDTHPOINTS=%d -dDEVICEHEIGHTPOINTS=%d", - gs_opts, opts.papersize); + gs_opts, fix (opts.papersize)); if (opts.papersize(1) > opts.papersize(2)) ## Lanscape mode: This option will result in automatic rotation of the ## document page if the requested page size matches one @@ -108,7 +108,7 @@ gs_opts = sprintf ("%s -dFIXEDMEDIA", gs_opts); ## "pageoffset" is relative to the coordinates, not the BBox LLHC. str = sprintf ("%s [%d %d] %s", "<< /Margins [0 0] /.HWMargins [0 0 0 0] /PageOffset", - opts.pageoffset, ">> setpagedevice"); + fix (opts.pageoffset), ">> setpagedevice"); offset_ps = {"%!PS-Adobe-3.0", str, "%%EOF"}; if (isfield (opts, "offsetfile")) offsetfile = opts.offsetfile; diff --git a/scripts/plot/util/private/__gnuplot_print__.m b/scripts/plot/util/private/__gnuplot_print__.m --- a/scripts/plot/util/private/__gnuplot_print__.m +++ b/scripts/plot/util/private/__gnuplot_print__.m @@ -220,6 +220,8 @@ f = sprintf ("%d", 2 * opts.fontsize); endif case "svg" + ## FIXME: Why does svg format use round on the fontsize while + ## other terminals don't? if (! isempty (opts.font) && ! isempty (opts.fontsize)) fontsize = round (opts.fontsize * 0.75); f = sprintf ('fname "%s" fsize %d', opts.font, fontsize); diff --git a/scripts/plot/util/private/__go_draw_axes__.m b/scripts/plot/util/private/__go_draw_axes__.m --- a/scripts/plot/util/private/__go_draw_axes__.m +++ b/scripts/plot/util/private/__go_draw_axes__.m @@ -617,7 +617,7 @@ usingclause{data_idx} = usingclause{data_idx - 1}; data{data_idx} = data{data_idx - 1}; withclause{data_idx} = sprintf ("with %s linestyle %d", - style{2}, data_idx); + style{2}, data_idx); endif if (length (style) > 2) data_idx++; @@ -629,7 +629,7 @@ usingclause{data_idx} = usingclause{data_idx - 1}; data{data_idx} = data{data_idx - 1}; withclause{data_idx} = sprintf ("with %s linestyle %d", - style{3}, data_idx); + style{3}, data_idx); endif case "patch" @@ -1782,6 +1782,8 @@ # # This means that if an alternative size is used, gnuplot will use an # inappropriate spacing in the legend by default. + ## FIXME: Are fractional spacing specifications allowed? Or should this + ## number be rounded? spc = s / 10 * 1.25; spacing_spec = sprintf ("spacing %d", spc); diff --git a/scripts/plot/util/private/__go_draw_figure__.m b/scripts/plot/util/private/__go_draw_figure__.m --- a/scripts/plot/util/private/__go_draw_figure__.m +++ b/scripts/plot/util/private/__go_draw_figure__.m @@ -38,7 +38,7 @@ fputs (plot_stream, "set size 1, 1\n"); bg = get (h, "color"); if (isnumeric (bg)) - fprintf (plot_stream, "set obj 1 rectangle from screen 0,0 to screen 1,1 behind fc rgb \"#%02x%02x%02x\"\n", 255 * bg); + fprintf (plot_stream, "set obj 1 rectangle from screen 0,0 to screen 1,1 behind fc rgb \"#%02x%02x%02x\"\n", round (255 * bg)); bg_is_set = true; else bg_is_set = false; @@ -114,7 +114,7 @@ endif endfor if (bg_is_set) - fprintf (plot_stream, "set border linecolor rgb \"#%02x%02x%02x\"\n", 255 * (1 - bg)); + fprintf (plot_stream, "set border linecolor rgb \"#%02x%02x%02x\"\n", round (255 * (1 - bg))); endif __go_draw_axes__ (kids(i), plot_stream, enhanced, mono, bg_is_set, false, hlgnd); @@ -140,7 +140,7 @@ set (kids(i), "units", "normalized"); fg = get (kids(i), "color"); if (isnumeric (fg) && strcmp (get (kids(i), "visible"), "on")) - fprintf (plot_stream, "set obj 2 rectangle from graph 0,0 to graph 1,1 behind fc rgb \"#%02x%02x%02x\"\n", 255 * fg); + fprintf (plot_stream, "set obj 2 rectangle from graph 0,0 to graph 1,1 behind fc rgb \"#%02x%02x%02x\"\n", round (255 * fg)); fg_is_set = true; fg_was_set = true; elseif (fg_was_set) @@ -151,7 +151,7 @@ fg_is_set = false; endif if (bg_is_set) - fprintf (plot_stream, "set border linecolor rgb \"#%02x%02x%02x\"\n", 255 * (1 - bg)); + fprintf (plot_stream, "set border linecolor rgb \"#%02x%02x%02x\"\n", round (255 * (1 - bg))); endif ## Find if this axes has an associated legend axes and pass it ## to __go_draw_axes__ diff --git a/scripts/sparse/bicg.m b/scripts/sparse/bicg.m --- a/scripts/sparse/bicg.m +++ b/scripts/sparse/bicg.m @@ -98,6 +98,8 @@ if (nargin < 4 || isempty (maxit)) maxit = min (rows (b), 20); + else + maxit = fix (maxit); endif if (nargin < 5 || isempty (M1)) diff --git a/scripts/sparse/qmr.m b/scripts/sparse/qmr.m --- a/scripts/sparse/qmr.m +++ b/scripts/sparse/qmr.m @@ -112,6 +112,8 @@ if (nargin < 4 || isempty (maxit)) maxit = min (rows (b), 20); + else + maxit = fix (maxit); endif if (nargin < 5 || isempty (M1)) diff --git a/scripts/strings/mat2str.m b/scripts/strings/mat2str.m --- a/scripts/strings/mat2str.m +++ b/scripts/strings/mat2str.m @@ -70,6 +70,10 @@ n = 15; elseif (isempty (n)) n = 15; # Default precision + elseif (numel (n) > 2) + error ("mat2str: N must have only 1 or 2 elements"); + else + n = fix (n); endif x_islogical = islogical (x); @@ -144,4 +148,5 @@ %!error mat2str (1,2,3,4) %!error mat2str (["Hello"]) %!error mat2str (ones (3,3,2)) +%!error mat2str (ones (3,3), [1 2 3]) diff --git a/scripts/strings/validatestring.m b/scripts/strings/validatestring.m --- a/scripts/strings/validatestring.m +++ b/scripts/strings/validatestring.m @@ -67,7 +67,7 @@ position = 0; ## Process input arguments if (! isempty (varargin) && isnumeric (varargin{end})) - position = varargin{end}; + position = fix (varargin{end}); varargin(end) = []; endif diff --git a/scripts/testfun/assert.m b/scripts/testfun/assert.m --- a/scripts/testfun/assert.m +++ b/scripts/testfun/assert.m @@ -641,7 +641,7 @@ cout = cell (numel (erridx), 1); tmp = cell (1, numel (matsize)); - [tmp{:}] = ind2sub (matsize, erridx (:)); + [tmp{:}] = ind2sub (matsize, erridx(:)); subs = [tmp{:}]; if (numel (matsize) == 2) subs = subs(:, matsize != 1);