Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7864605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:50:06+00:00 2026-06-02T23:50:06+00:00

I have a function that parse a JSON text and return a new structure

  • 0

I have a function that parse a JSON text and return a new structure called EZapiEntry.
When I check the value of result every thing is OK.

After using this function in an athor c file. I get wrong results.

Code of the function:

EZapiEntry parseEntry()
 {
    EZapiEntry   result;
    json_t      *entryJson;
    entryJson = json_object_get(root,"data");
    unsigned int i=0;
    EZuc8* maskString=json_string_value(json_object_get(entryJson,"mask"));
    result.uiKeySize = json_integer_value(json_object_get(entryJson,"keySize"));
    result.uiResultSize = json_integer_value(json_object_get(entryJson,"resultSize"));
    EZuc8 val1[result.uiKeySize];   
    hexStringToBytes(json_string_value(json_object_get(entryJson,"key")),val1);
    result.pucKey = val1;   
    EZuc8 val2[result.uiResultSize];
    hexStringToBytes(json_string_value(json_object_get(entryJson,"result")),val2);  
    result.pucResult = val2;
    EZuc8 val3[strlen(maskString)];
    hexStringToBytes(maskString,val3);  
    result.pucMask = val3;
    result.uiProfile = json_integer_value(json_object_get(entryJson,"profile"));
        printf("\nkeySize :  %u  ",result.uiKeySize);
        printf("\nResultSize :  %u  ",result.uiResultSize);
        printf("\nkey :    ");
        for (i = 0 ; i <result.uiKeySize ; i++)
        {
            printf("%02x",result.pucKey[i]);
        }
        printf("\nresult :    ");
        for (i = 0 ; i <result.uiResultSize ; i++)
        {
           printf("%02x",result.pucResult[i]);
        }
        printf("\nmask :    ");
        for (i = 0 ; i <strlen(maskString) ; i++)
        {
          printf("%02x",result.pucMask[i]);
         }  
        printf("\nprofile :    ");
        printf("%u",result.uiProfile);  
    return result;
 }

code of the use of the function :

 entry=parseEntry();
   printf("\nkeySize2 :  %u  ",entry.uiKeySize);
   printf("\nResultSize2:  %u  ",entry.uiResultSize);
   printf("\nkey2 :    ");
    for (i = 0 ; i <entry.uiKeySize ; i++)
    {
       printf("%02x",entry.pucKey[i]);
    }
   printf("\nresult2 :    ");
    for (i = 0 ; i <entry.uiResultSize ; i++)
    {
       printf("%02x",entry.pucResult[i]);
    }
   printf("\nprofile2 :    ");
   printf("%u",entry.uiProfile);

And this is the result :

keySize :  1  
ResultSize :  16  
key :    03
result :    aaaaaa11445544ff00112233445544ff
mask :    0000000a
profile :    0
keySize2 :  1  
ResultSize2:  16  
key2 :    bf
result2 :    bfb985b0102e765c00112233445544ff
profile2 :    0

The first values for example Result1 is the correct one. The second is the wrong one

I am really stack, i can’t find the problem !
Is there any Help ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T23:50:08+00:00Added an answer on June 2, 2026 at 11:50 pm

    This will result in a dangling pointer after the function returns:

    EZuc8 val2[result.uiResultSize];
    hexStringToBytes(json_string_value(json_object_get(entryJson,"result")),val2);  
    result.pucResult = val2;
    

    as val2 will no longer exist when parseEntry() returns. Similar problem for val1 and val3. Instead of using VLA malloc() directly to the relevant member:

    result.pucResult = malloc(sizeof(EZuc8) * result.uiResultSize);
    hexStringToBytes(json_string_value(json_object_get(entryJson,"result")),
                     result.pucResult);
    

    Remember to free() the dynamically allocated memory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dojo.xhrGet that return an correct array of object : <script type=text/javascript>
I notice that when using lambdas: { name: Willy, wrapped: function() { return function(text)
I have a recursion function that parses an object/array with a global variable. If
I currently have a function that grabs the browser windows uri, parses out the
I have a function, parseQuery, that parses a SQL query into an abstract representation
I have created a function in PHP that calls a webservice and parses through
So I have function that formats a date to coerce to given enum DateType{CURRENT,
In my Java code I have function that gets file from the client in
I have function Start() that is fired on ready. When I click on .ExampleClick
I have a function that calculates the distance between two GPS coordinates. I then

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.