Skip to content

Commit

Permalink
Small code fixes for d.legend and Cairo_Text (#1076)
Browse files Browse the repository at this point in the history
MaxLabel needs to hold buff plus one (e.g. for a space) to avoid several
warnings: sprintf may write a terminating nul past the end of the destination
[-Wformat-overflow=] with GCC.

D_save_command needs to be called only one per standard module call
(although should be removed in the future). draw() is called twice with bg drawing.

D_text call seems to be badly indented, but in a correct branch, so fixing
warning: this if clause does not guard... [-Wmisleading-indentation].

Various iconv documetations specify the retun value on error as (iconv_t) -1
for iconv_open, so test specifically for that and avoid
warning: ordered comparison of pointer with integer zero [-Wextra].

Fix also a typo and empty line at the end of file.
  • Loading branch information
wenzeslaus committed Nov 18, 2020
1 parent 32bb3de commit b6e41c1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
5 changes: 2 additions & 3 deletions display/d.legend/draw.c
Expand Up @@ -67,7 +67,7 @@ void draw(const char *map_name, int maptype, int color, int thin, int lines,
double coef;
double ppl;
double bb,bt,bl,br;
char MaxLabel[512];
char MaxLabel[513];
double num;
int MaxLabelW, LabelW;

Expand Down Expand Up @@ -594,7 +594,7 @@ void draw(const char *map_name, int maptype, int color, int thin, int lines,
}
if (color)
D_use_color(color);
D_text(buff);
D_text(buff);
}
}
} /* for */
Expand Down Expand Up @@ -1360,5 +1360,4 @@ void draw(const char *map_name, int maptype, int color, int thin, int lines,
}

}
D_save_command(G_recreate_command());
}
1 change: 1 addition & 0 deletions display/d.legend/main.c
Expand Up @@ -486,6 +486,7 @@ int main(int argc, char **argv)
opt_at, opt_fontsize, opt_tstep, opt_range, histo,
hidestr, log_scale, 1, digits, units);

D_save_command(G_recreate_command());
D_close_driver();

exit(EXIT_SUCCESS);
Expand Down
5 changes: 2 additions & 3 deletions lib/cairodriver/text.c
Expand Up @@ -8,7 +8,7 @@
This program is free software under the GNU General Public License
(>=v2). Read the file COPYING that comes with GRASS for details.
\author Lars Ahlzen <lars ahlzen.com> (original contibutor)
\author Lars Ahlzen <lars ahlzen.com> (original contributor)
\author Glynn Clements
*/

Expand Down Expand Up @@ -42,7 +42,7 @@ static char *convert(const char *in)
size_t ret;
iconv_t cd;

if ((cd = iconv_open("UTF-8", encoding)) < 0)
if ((cd = iconv_open("UTF-8", encoding)) == (iconv_t) -1)
G_fatal_error(_("Unable to convert from <%s> to UTF-8"),
encoding);

Expand Down Expand Up @@ -340,4 +340,3 @@ void Cairo_font_info(char ***list, int *count)
font_list_fc(list, count, 1);
#endif
}

0 comments on commit b6e41c1

Please sign in to comment.