[GRASS-dev] new v.support metadata module
Paul Kelly
paul-grass at stjohnspoint.co.uk
Thu Mar 15 07:49:13 EDT 2007
Hello Markus
On Thu, 15 Mar 2007, Markus Neteler wrote:
> Known bug: long comments are crashing it, I don't know why (C string programming
> and me are somewhat orthogonal to each other) - please someone take a look.
G_strcat() does not enlarge the memory allocated for the string you are
appending to - it just adds the new string on to the end but the memory
bytes after the end were probably reserved for something else, so that is
a problem. You could enlarge the space allocated for Map.head.line_3 using
perhaps G_realloc() before appending the new comment to it, but IMHO that
would be a bad idea too as it is bad to modify the internal parameters of
the struct Map_info without using vector library functions to do it.
I think it would be better to use a temporary string for the new comment.
Something like:
char *temp;
G_asprintf(&temp, "%s%s", Map.head.line_3, comment->answer);
Vect_set_comment(&Map, temp);
Then you are never messing directly with the internals of the Map_info
struct and G_asprintf() will ensure enough memory is allocated to hold the
two strings concatenated together.
But I wonder too should there not be a newline character in there
somewhere as the documentation says the comment text is added to the next
line? Also don't understand the second example where a space " " is
appended to the comment?
Also it might be useful to have a flag that would totally over-write the
comment rather than appending, with a big warning in the description of
course.
Paul
More information about the grass-dev
mailing list