
Passing strings through registers to the PLI
Excerpts from comp.lang.verilog: 8 6-May-99 Re: Passing strings by Mark Curry
Quote:
>field = malloc( strlen( field_temp ) );
>strcpy( field, field_temp );
This code would allocate one byte less than the required space because strlen()
returns the length of the string *without* including the terminating null byte.
The correct allocation would be:
field = malloc(strlen(field_temp) + 1);
Incidentally, you can use strdup() to do both the allocate and copy steps at
once:
field = strdup(field_temp);
Of course, you should check the return value to make sure you got what you
asked for!
Berend