re PR libobjc/9751 (malloc of strlen, not strlen+1)

2006-01-24  David Ayers  <d.ayers@inode.at>

	PR libobjc/9751
	* gc.c (class_ivar_set_gcinvisible): Replace strncpy with memcpy
	and insure the new strings are '\0' termintated.

From-SVN: r110187
This commit is contained in:
David Ayers 2006-01-25 00:37:24 +01:00 committed by David Ayers
parent e7968bd850
commit 801a91f9c2
2 changed files with 18 additions and 8 deletions

View File

@ -1,3 +1,9 @@
2006-01-24 David Ayers <d.ayers@inode.at>
PR libobjc/9751
* gc.c (class_ivar_set_gcinvisible): Replace strncpy with memcpy
and insure the new strings are '\0' termintated.
2006-01-24 David Ayers <d.ayers@inode.at>
PR libobjc/13946

View File

@ -397,30 +397,34 @@ class_ivar_set_gcinvisible (Class class, const char *ivarname,
if (*type == _C_GCINVISIBLE)
{
char *new_type;
size_t len;
if (gc_invisible || ! __objc_ivar_pointer (type))
return; /* The type of the variable already matches the
requested gc_invisible type */
/* The variable is gc_invisible and we have to reverse it */
new_type = objc_atomic_malloc (strlen (ivar->ivar_type));
strncpy (new_type, ivar->ivar_type,
(size_t)(type - ivar->ivar_type));
/* The variable is gc_invisible so we make it gc visible. */
new_type = objc_atomic_malloc (strlen(ivar->ivar_type));
len = (type - ivar->ivar_type);
memcpy (new_type, ivar->ivar_type, len);
new_type[len] = 0;
strcat (new_type, type + 1);
ivar->ivar_type = new_type;
}
else
{
char *new_type;
size_t len;
if (! gc_invisible || ! __objc_ivar_pointer (type))
return; /* The type of the variable already matches the
requested gc_invisible type */
/* The variable is gc visible and we have to make it gc_invisible */
new_type = objc_malloc (strlen (ivar->ivar_type) + 2);
strncpy (new_type, ivar->ivar_type,
(size_t)(type - ivar->ivar_type));
/* The variable is gc visible so we make it gc_invisible. */
new_type = objc_malloc (strlen(ivar->ivar_type) + 2);
len = (type - ivar->ivar_type);
memcpy (new_type, ivar->ivar_type, len);
new_type[len] = 0;
strcat (new_type, "!");
strcat (new_type, type);
ivar->ivar_type = new_type;