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

  • SEARCH
  • Home
  • 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 6331645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:06:36+00:00 2026-05-24T18:06:36+00:00

When the following code is compiled with LLVM Compiler, it doesn’t operate correctly. (i

  • 0

When the following code is compiled with LLVM Compiler, it doesn’t operate correctly.
(i doesn’t increase.)
It operates correctly when compiling with GCC 4.2.
Is this a bug of LLVM Compiler?

#include <stdio.h>
#include <string.h>

void BytesFromHexString(unsigned char *data, const char *string) {
    printf("bytes:%s:", string);
    int len = (int)strlen(string);
    for (int i=0; i<len; i+=2) {
        unsigned char x;
        sscanf((char *)(string + i), "%02x", &x);
        printf("%02x", x);
        data[i] = x;
    }
    printf("\n");
}

int main (int argc, const char * argv[])
{
    // insert code here...
    unsigned char data[64];
    BytesFromHexString(data, "4d4f5cb093fc2d3d6b4120658c2d08b51b3846a39b51b663e7284478570bcef9");
    return 0;
}
  • 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-05-24T18:06:37+00:00Added an answer on May 24, 2026 at 6:06 pm

    For sscanf you’d use %2x instead of %02x. Furthermore, %2x indicates that an extra int* argument will be passed. But you’re passing an unsigned char*. And finally, sscanf takes a const char* as first argument, so there’s no need for that cast.

    So give this a try :

    int x;
    sscanf((string + i), "%2x", &x);
    

    EDIT : to clarify why this change resolves the issue : in your code, sscanf tried to write sizeof(int) bytes in a memory location (&x) that could only hold sizeof(unsigned char) bytes (ie. 1 byte). So, you were overwriting a certain amount of memory. This overwritten memory could very well have been (part of) the i variable.

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

Sidebar

Related Questions

I have the following code compiled by gcc: #include <iostream> using namespace std; class
The following code int _main() {return 0;} Compiled using the command: gcc -s -nostdlib
Following code does compile in gcc 4.5 but it is not being compiled in
The following code gives a different number of destructors when compiled on GCC and
i have the following code compiled with GCC 4.2 / XCode. template <typename T>
Following code, when compiled and run with g++, prints '1' twice, whereas I expect
I compiled the following code as a shared library using g++ -shared ... :
the following piece of C++ code compiled two years ago in a suse 10.1
The following code is generating warning C6284 when compiled with /analyze on MSVC 2008
I come into a strange problem in pthread programming I've compiled the following code

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.