gpt4 book ai didi

Ubuntu 上的 strdup() 崩溃

转载 作者:太空宇宙 更新时间:2023-11-04 04:02:14 25 4
gpt4 key购买 nike

当我尝试在 Ubuntu 上运行时,我的 C 程序出现段错误。这是堆栈跟踪。感谢任何帮助

0  0x015383f1 in ?? () from /lib/tls/i686/cmov/libc.so.6
#1 0x01538075 in strdup () from /lib/tls/i686/cmov/libc.so.6
#2 0x00c0a4af in cvtToString (ign=0xc10b80, target=0x83ba0a8, off=56,
source=0x0, setter=0xc044c3 <UxString_SetValue>) at xmlSerialPrimitives.c:28
#3 0x00c09adb in _setValue (xs=0x83b3520, inst=0x83ba0a8 "\020", prop=0xc103dc,
value=0x0) at xmlDeserializer.c:214
#4 0x00c09b71 in ctSetValue (xs=0x83b3520, property=0xc103dc, parent=0x83ba0a8,
val=0x0) at xmlDeserializer.c:237
#5 0x00c0a1aa in _closeElement (xs=0x83b3520, element=0x83ba1a0)
at xmlDeserializer.c:419
#6 0x00c0a3da in xmlDeserialize (xs=0x83b3520, xtr=0x83b6218)
at xmlDeserializer.c:533
#7 0x00c0ab14 in xmlDeserializeFromFile (xs=0x83b3520,
file=0x83b34f0 "/usr/v/xlayout.xml")
at xmlSerializer.c:60
#8 0x00c07280 in load_uxUserModel (
file=0x83b34f0 "/usr/v/xlayout.xml", data=0xbffff4dc)
at UxUserModel.c:718
#9 0x00c073d0 in UxUserModel_LoadUserModel (name=0x8148e60 "x.xml")
at UxUserModel.c:771
#10 0x00bf7f5d in UxModelLoad (umif=0x8397c58, filename=0x8148e60 "x.xml")

这是崩溃的函数

static int cvtToString( PCType * ign, void * target, int off, char * source, 
void_f setter)
{
/* do we want to copy the string? */
if (source && strncmp( source, "usermodel://", 12) == 0)
return 0;
source = strdup( source);
if (setter)
(*setter)( target, source);
else
(void) memcpy( target+off, &source, sizeof(char*));

return 1;
}

最佳答案

if (!source || !strncmp( source, "usermodel://", 12))
return 0;

顺便说一句:这一行:

(void) memcpy( target+off, &source, sizeof(char*));

尝试对空指针执行算术运算。编译器应该(至少)提示。

关于Ubuntu 上的 strdup() 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10390012/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com