bilwis / RMD

RMD
0 stars 0 forks source link

Null-terminator crop during char[] parameter copy in Part construction. #3

Closed bilwis closed 10 years ago

bilwis commented 10 years ago

During construction of Part (and its subclasses), string (or char*) parameters are copied to the internal variable using the following method:

char* buf = (char*)malloc(strlen(param)); this->param = strcpy(buf, param); buf = NULL;

strlen() however returns the number of characters in a char[] without the null terminator. Therefore it allocated a byte less than needed and the terminator is cropped during strcpy(). It may be wise to use sizeof() instead or add one byte to the malloc() request.

bilwis commented 10 years ago

Also add error catching if malloc() fails and returns NULL.