Make sure type strings are nul terminated.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@26119 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2008-02-22 12:59:30 +00:00
parent eecde45785
commit 0c30cbd8c0
5 changed files with 46 additions and 14 deletions

View file

@ -1,3 +1,10 @@
2008-02-22 Richard Frith-Macdonald <rfm@gnu.org>
* Source/mframe/mframe.head: Change function arguments
* Source/mframe.m: Support nul termination of type strings
* Source/NSMethodSignature.m: nul terminate type strings
* Source/NSObjCRuntime.m: update for changed function args
2008-02-21 Richard Frith-Macdonald <rfm@gnu.org>
* Headers/Foundation/NSKeyValueCoding.h:

View file

@ -170,13 +170,24 @@
if (_info == 0)
{
const char *types = _methodTypes;
char *outTypes;
unsigned int i;
_info = NSZoneMalloc(NSDefaultMallocZone(),
sizeof(NSArgumentInfo)*(_numArgs+1));
/* Allocate space enough for an NSArgumentInfo structure for each
* argument (including the return type), and enough space to hold
* the type information for each argument as a nul terminated
* string.
*/
outTypes = NSZoneMalloc(NSDefaultMallocZone(),
sizeof(NSArgumentInfo)*(_numArgs+1) + strlen(types)*2);
_info = (NSArgumentInfo*)outTypes;
outTypes = outTypes + sizeof(NSArgumentInfo)*(_numArgs+1);
/* Fill in the full argment information for each arg.
*/
for (i = 0; i <= _numArgs; i++)
{
types = mframe_next_arg(types, &_info[i]);
types = mframe_next_arg(types, &_info[i], outTypes);
outTypes += strlen(outTypes) + 1;
}
}
return _info;

View file

@ -109,7 +109,7 @@ const char *
NSGetSizeAndAlignment(const char *typePtr, unsigned *sizep, unsigned *alignp)
{
NSArgumentInfo info;
typePtr = mframe_next_arg(typePtr, &info);
typePtr = mframe_next_arg(typePtr, &info, 0);
if (sizep)
*sizep = info.size;
if (alignp)

View file

@ -202,11 +202,14 @@ mframe_build_signature(const char *typePtr, int *size, int *narg, char *buf)
}
/*
* Step through method encoding information extracting details.
/* Step through method encoding information extracting details.
* If outTypes is non-nul then we copy the argument type into
* the buffer as a nul terminated string and use the values in
* this buffer as the types in info, rather than pointers to
* positions in typePtr
*/
const char *
mframe_next_arg(const char *typePtr, NSArgumentInfo *info)
mframe_next_arg(const char *typePtr, NSArgumentInfo *info, char *outTypes)
{
NSArgumentInfo local;
BOOL flag;
@ -354,7 +357,7 @@ mframe_next_arg(const char *typePtr, NSArgumentInfo *info)
{
typePtr++;
}
typePtr = mframe_next_arg(typePtr, &local);
typePtr = mframe_next_arg(typePtr, &local, 0);
info->size = length * ROUND(local.size, local.align);
info->align = local.align;
typePtr++; /* Skip end-of-array */
@ -380,7 +383,7 @@ mframe_next_arg(const char *typePtr, NSArgumentInfo *info)
*/
if (*typePtr != _C_STRUCT_E)
{
typePtr = mframe_next_arg(typePtr, &local);
typePtr = mframe_next_arg(typePtr, &local, 0);
if (typePtr == 0)
{
return 0; /* error */
@ -395,7 +398,7 @@ mframe_next_arg(const char *typePtr, NSArgumentInfo *info)
*/
while (*typePtr != _C_STRUCT_E)
{
typePtr = mframe_next_arg(typePtr, &local);
typePtr = mframe_next_arg(typePtr, &local, 0);
if (typePtr == 0)
{
return 0; /* error */
@ -434,7 +437,7 @@ mframe_next_arg(const char *typePtr, NSArgumentInfo *info)
}
while (*typePtr != _C_UNION_E)
{
typePtr = mframe_next_arg(typePtr, &local);
typePtr = mframe_next_arg(typePtr, &local, 0);
if (typePtr == 0)
{
return 0; /* error */
@ -462,6 +465,17 @@ mframe_next_arg(const char *typePtr, NSArgumentInfo *info)
return 0;
}
/* Copy tye type information into the buffer if provided.
*/
if (outTypes != 0)
{
unsigned len = typePtr - info->type;
strncpy(outTypes, info->type, len);
outTypes[len] = '\0';
info->type = outTypes;
}
/*
* May tell the caller if the item is stored in a register.
*/
@ -499,7 +513,6 @@ mframe_next_arg(const char *typePtr, NSArgumentInfo *info)
return typePtr;
}
/* Return the number of arguments that the method MTH expects. Note
that all methods need two implicit arguments `self' and `_cmd'. */

View file

@ -18,7 +18,8 @@
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02111 USA.
*/
#ifndef __mframe_h_GNUSTEP_BASE_INCLUDE
@ -96,7 +97,7 @@ mframe_handle_return(const char* type, void* retval, arglist_t argFrame);
* Step through method encoding information extracting details.
*/
const char *
mframe_next_arg(const char *typePtr, NSArgumentInfo *info);
mframe_next_arg(const char *typePtr, NSArgumentInfo *info, char *outTypes);
/*
* Generate method encoding with stack/register offsets from a simple