Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. an problem about memset() in Qt
Forum Updated to NodeBB v4.3 + New Features

an problem about memset() in Qt

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 637 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jimk123
    wrote on last edited by
    #1

    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?

    jsulmJ 1 Reply Last reply
    0
    • J jimk123

      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?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • J jimk123 has marked this topic as solved on
      • J Offline
        J Offline
        jimk123
        wrote on last edited by
        #3

        well, I change another new dll, it's ok...

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved