Hi all,
I was looking at g.copy source and now I have some simple questions:
1) Is it safe to pass int to G_calloc(), as it expects size_t?
2) Is it safe to G_malloc() fixed amount for parser's option
description? (opt->description)
3) Why G_warning isn't a viod function? It always returns 0 and none
of GRASS modules performs check for it's return value.
Thanks for answers to GRASS C guru's.
Maris.
Index: general/manage/cmd/copy.c
===================================================================
RCS file: /home/grass/grassrepository/grass6/general/manage/cmd/copy.c,v
retrieving revision 1.17
diff -u -u -r1.17 copy.c
--- general/manage/cmd/copy.c 20 Jul 2007 22:33:56 -0000 1.17
+++ general/manage/cmd/copy.c 15 Oct 2007 17:05:52 -0000
@@ -41,19 +41,19 @@
"search path and location to the appropriate element "
"directories under the user's current mapset.");
- parm = (struct Option **) G_calloc (nlist, sizeof(struct Option *));
+ parm = (struct Option **) G_calloc ((size_t)nlist, sizeof(struct Option *));
for (n = 0; n < nlist; n++)
{
p = parm[n] = G_define_option();
p->key = list[n].alias;
- p->key_desc="from,to";
+ p->key_desc=_("from,to");
p->type = TYPE_STRING;
p->required = NO;
p->multiple = NO;
- p->gisprompt = G_malloc (64);
+ p->gisprompt = G_malloc (strlen("old,%s,%s")+strlen(list[n].mainelem)+strlen(list[n].maindesc)+2);
sprintf (p->gisprompt, "old,%s,%s", list[n].mainelem, list[n].maindesc);
- p->description = G_malloc (64);
+ p->description = G_malloc (strlen(_("%s file(s) to be copied"))+strlen(list[n].alias)+2);
sprintf (p->description, _("%s file(s) to be copied"), list[n].alias);
}
Index: general/manage/cmd/list.c
===================================================================
RCS file: /home/grass/grassrepository/grass6/general/manage/cmd/list.c,v
retrieving revision 1.7
diff -u -u -r1.7 list.c
--- general/manage/cmd/list.c 12 Feb 2007 15:01:02 -0000 1.7
+++ general/manage/cmd/list.c 15 Oct 2007 17:05:52 -0000
@@ -29,7 +29,8 @@
int
main (int argc, char *argv[])
{
- int i, n, len;
+ int i, n;
+ size_t len;
struct GModule *module;
struct Option *mapset;
struct Flag *full;
@@ -44,11 +45,11 @@
element = G_define_option();
element->key = "type";
- element->key_desc = "datatype";
+ element->key_desc = _("datatype");
element->type = TYPE_STRING;
element->required = YES;
element->multiple = YES;
- element->description = "Data type";
+ element->description = _("Data type");
for (len=0,n=0 ; n < nlist; n++)
len += strlen (list[n].alias)+1;
element->options = G_malloc(len);
Index: general/manage/cmd/remove.c
===================================================================
RCS file: /home/grass/grassrepository/grass6/general/manage/cmd/remove.c,v
retrieving revision 1.17
diff -u -u -r1.17 remove.c
--- general/manage/cmd/remove.c 30 May 2007 17:24:46 -0000 1.17
+++ general/manage/cmd/remove.c 15 Oct 2007 17:05:52 -0000
@@ -51,7 +51,7 @@
force_flag->key = 'f';
force_flag->description = _("Force remove");
- parm = (struct Option **) G_calloc (nlist, sizeof(struct Option *));
+ parm = (struct Option **) G_calloc ((size_t)nlist, sizeof(struct Option *));
for (n = 0; n < nlist; n++)
{
@@ -60,9 +60,9 @@
p->type = TYPE_STRING;
p->required = NO;
p->multiple = YES;
- p->gisprompt = G_malloc (64);
+ p->gisprompt = G_malloc (strlen("old,%s,%s")+strlen(list[n].mainelem)+strlen(list[n].maindesc)+2);
sprintf (p->gisprompt, "old,%s,%s", list[n].mainelem, list[n].maindesc);
- p->description = G_malloc (64);
+ p->description = G_malloc (strlen(_("%s file(s) to be removed"))+strlen(list[n].alias));
sprintf (p->description, _("%s file(s) to be removed"), list[n].alias);
}
Index: general/manage/cmd/rename.c
===================================================================
RCS file: /home/grass/grassrepository/grass6/general/manage/cmd/rename.c,v
retrieving revision 1.19
diff -u -u -r1.19 rename.c
--- general/manage/cmd/rename.c 20 Jul 2007 22:33:56 -0000 1.19
+++ general/manage/cmd/rename.c 15 Oct 2007 17:05:52 -0000
@@ -41,19 +41,19 @@
module->description =
_("Renames data base element files in the user's current mapset.");
- parm = (struct Option **) G_calloc (nlist, sizeof(struct Option *));
+ parm = (struct Option **) G_calloc ((size_t)nlist, sizeof(struct Option *));
for (n = 0; n < nlist; n++)
{
p = parm[n] = G_define_option();
p->key = list[n].alias;
- p->key_desc="old,new";
+ p->key_desc=_("old,new");
p->type = TYPE_STRING;
p->required = NO;
p->multiple = NO;
- p->gisprompt = G_malloc (64);
+ p->gisprompt = G_malloc (strlen("old,%s,%s")+strlen(list[n].mainelem)+strlen(list[n].maindesc)+2);
sprintf (p->gisprompt, "old,%s,%s", list[n].mainelem, list[n].maindesc);
- p->description = G_malloc (64);
+ p->description = G_malloc (strlen(_("%s file(s) to be renamed"))+strlen(list[n].alias)+2);
sprintf (p->description, _("%s file(s) to be renamed"), list[n].alias);
}
_______________________________________________
grass-dev mailing list
[email protected]
http://grass.itc.it/mailman/listinfo/grass-dev