an problem about memset() in Qt
-
I use Qt5.14.1 to call function from other dll. The exmaple code is below:
typedef int (*card1_GetPeopleName)(char*, int*); //funciont from an identify reader dll to get a man's name card1_GetPeopleName GetPeopleName; char buff[64]; int len = 0; memset(buff, 0, 64); //or memset(buff, 0, sizeof(buff)); GetPeopleName(buff, &len); //catch name in 'buff', and the length of name in 'len' memset(buff, 0, 64); GetPeopleName(buff, &len); memset(buff, 0, 64); GetPeopleName(buff, &len); memset(buff, 0, 64); GetPeopleName(buff, &len); memset(buff, 0, 64); GetPeopleName(buff, &len); //repeat 5 times, it crashes, and with information 'segmentation fault'
If I replace 'memset' with
for(int n = 0; n < 64; n ++) buff[n]=0;
memset(buff, 0, 64);
and repeat 5 times, it's ok.
I think 'memset' is just only set memory from 'buff' to 'buff+64',but the execution result is different with 'for'.I test the same code in vc(use memset), it's OK too.
So is there any difference in 'memset' between Qt and vc??Can anyone help me?
-
I use Qt5.14.1 to call function from other dll. The exmaple code is below:
typedef int (*card1_GetPeopleName)(char*, int*); //funciont from an identify reader dll to get a man's name card1_GetPeopleName GetPeopleName; char buff[64]; int len = 0; memset(buff, 0, 64); //or memset(buff, 0, sizeof(buff)); GetPeopleName(buff, &len); //catch name in 'buff', and the length of name in 'len' memset(buff, 0, 64); GetPeopleName(buff, &len); memset(buff, 0, 64); GetPeopleName(buff, &len); memset(buff, 0, 64); GetPeopleName(buff, &len); memset(buff, 0, 64); GetPeopleName(buff, &len); //repeat 5 times, it crashes, and with information 'segmentation fault'
If I replace 'memset' with
for(int n = 0; n < 64; n ++) buff[n]=0;
memset(buff, 0, 64);
and repeat 5 times, it's ok.
I think 'memset' is just only set memory from 'buff' to 'buff+64',but the execution result is different with 'for'.I test the same code in vc(use memset), it's OK too.
So is there any difference in 'memset' between Qt and vc??Can anyone help me?
@jimk123 memset has nothing to do with Qt.
If it crashes then run through debugger and post the stack trace after crash.
You did not post the what the function GetPeopleName is pointing to is actually doing, I guess the crash is inside that function. -