mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-04 05:40:54 +00:00
fix behavior safety checks
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@29846 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
0d5498e121
commit
ded18f910d
1 changed files with 34 additions and 5 deletions
|
@ -788,12 +788,41 @@ GSObjCAddClassBehavior(Class receiver, Class behavior)
|
||||||
Method *methods;
|
Method *methods;
|
||||||
Class behavior_super_class = class_getSuperclass(behavior);
|
Class behavior_super_class = class_getSuperclass(behavior);
|
||||||
|
|
||||||
NSCAssert(NO == class_isMetaClass(receiver), NSInvalidArgumentException);
|
if (YES == class_isMetaClass(receiver))
|
||||||
NSCAssert(NO == class_isMetaClass(behavior), NSInvalidArgumentException);
|
{
|
||||||
|
fprintf(stderr, "Trying to add behavior (%s) to meta class (%s)\n",
|
||||||
NSCAssert2(class_getInstanceSize(receiver) < class_getInstanceSize(behavior),
|
|
||||||
@"Trying to add behavior (%s) with instance size larger than class (%s)",
|
|
||||||
class_getName(behavior), class_getName(receiver));
|
class_getName(behavior), class_getName(receiver));
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
if (YES == class_isMetaClass(behavior))
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Trying to add meta class as behavior (%s) to (%s)\n",
|
||||||
|
class_getName(behavior), class_getName(receiver));
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
if (class_getInstanceSize(receiver) < class_getInstanceSize(behavior))
|
||||||
|
{
|
||||||
|
const char *b = class_getName(behavior);
|
||||||
|
const char *r = class_getName(receiver);
|
||||||
|
|
||||||
|
#ifdef NeXT_Foundation_LIBRARY
|
||||||
|
fprintf(stderr, "Trying to add behavior (%s) with instance "
|
||||||
|
"size larger than class (%s)\n", b, r);
|
||||||
|
abort();
|
||||||
|
#else
|
||||||
|
/* As a special case we allow adding GSString/GSCString to the
|
||||||
|
* constant string class ... since we know the base library
|
||||||
|
* takes care not to access non-existent instance variables.
|
||||||
|
*/
|
||||||
|
if ((strcmp(b, "GSCString") && strcmp(b, "GSString"))
|
||||||
|
|| (strcmp(r, "NSConstantString") && strcmp(r, "NXConstantString")))
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Trying to add behavior (%s) with instance "
|
||||||
|
"size larger than class (%s)\n", b, r);
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
BDBGPrintf("Adding behavior to class %s\n", class_getName(receiver));
|
BDBGPrintf("Adding behavior to class %s\n", class_getName(receiver));
|
||||||
BDBGPrintf(" instance methods from %s\n", class_getName(behavior));
|
BDBGPrintf(" instance methods from %s\n", class_getName(behavior));
|
||||||
|
|
Loading…
Reference in a new issue