YYModel icon indicating copy to clipboard operation
YYModel copied to clipboard

crash 在YYClassMethodInfo initWithMethod方法

Open iphone-andy opened this issue 8 years ago • 6 comments

`- (instancetype)initWithMethod:(Method)method {

if (!method) return nil;
self = [super init];
_method = method;
_sel = method_getName(method);
_imp = method_getImplementation(method);
const char *name = sel_getName(_sel);
if (name) {
    _name = [NSString stringWithUTF8String:name];
}
const char *typeEncoding = method_getTypeEncoding(method);
if (typeEncoding) {
    _typeEncoding = [NSString stringWithUTF8String:typeEncoding];
}
char *returnType = method_copyReturnType(method);
if (returnType) {
    _returnTypeEncoding = [NSString stringWithUTF8String:returnType];
    free(returnType);
}
unsigned int argumentCount = method_getNumberOfArguments(method);
if (argumentCount > 0) {
    NSMutableArray *argumentTypes = [NSMutableArray new];
    for (unsigned int i = 0; i < argumentCount; i++) {
        char *argumentType = method_copyArgumentType(method, i);
        NSString *type = argumentType ? [NSString stringWithUTF8String:argumentType] : nil;
        [argumentTypes addObject:type ? type : @""];
        if (argumentType) free(argumentType);
    }
    _argumentTypeEncodings = argumentTypes;
}
return self;

}`

crash在stringWithUTF8String上,感觉在for循环里的

char *argumentType = method_copyArgumentType(method, i); NSString *type = argumentType ? [NSString stringWithUTF8String:argumentType] : nil;

两句,stringWithUTF8String 方法使用里写了Raises an exception if bytes is NULL,但代码里看着做了判断,所以暂时先放在这、

iphone-andy avatar Jan 05 '17 06:01 iphone-andy

同样crash在这里, 在大项目中混用swift的时候, 会段在

// YYClassMethodInfo.m
- (instancetype)initWithMethod:(Method)method {
unsigned int argumentCount = method_getNumberOfArguments(method); }

不知道是为什么, 所以我直接返回了. image

iOSleep avatar Apr 27 '17 04:04 iOSleep

这个问题还会修复吗,或者作者给个解决思路?

Tealloc avatar Apr 19 '18 08:04 Tealloc

@iOSleep +1

description对象的属性为Dictionary时crash

wanyakun avatar May 16 '18 03:05 wanyakun

description对象的属性为Dictionary时crash +1

0x5e avatar Sep 12 '18 07:09 0x5e

遇到同样的crash,请问这个问题现在修复了吗?

xiangqinfm avatar Oct 23 '18 08:10 xiangqinfm

+1 避免使用 yy_modelDescription 方法

beforeold avatar Mar 02 '19 05:03 beforeold