Menu

#7 crash caused by improper C string concatenation

_v0.0.7
open-fixed
None
5
2007-09-04
2007-08-26
Anonymous
No

> There is an error in your UtilConstStrCat() function.
>
> The length of memory malloc()'ed did not include an extra byte for the
> null character. I have included the corrected routine below.
>
>
> void UtilConstStrCat(t_char **str1, t_char *str2)
> {
> t_uint16 len1 = strlen(*str1);
>
> // Allocate new string
> t_char *newString = (t_char*)malloc(len1 + strlen(str2) + 1);
>
> // Copy strings into buffer
> strcpy(newString, *str1);
> strcpy(newString + len1, str2);
>
> // Assign buffer to string 1
> *str1 = newString;
> }

Discussion

  • Peter Dons Tychsen

    Logged In: YES
    user_id=760114
    Originator: NO

    Thanks for the fix.
    Will be included in v0.0.8

     
  • Peter Dons Tychsen

    • milestone: --> _v0.0.7
    • status: open --> open-accepted
     
  • Peter Dons Tychsen

    • status: open-accepted --> open-fixed
     
  • Peter Dons Tychsen

    • assigned_to: nobody --> donpedro2
     

Log in to post a comment.