This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

The 'sscanf' mistake

sscanf(buffer, "%d", &var1_1byte);

in the above case, var1_1byte is uint8_t (ie 1 byte char variable).
the "%d" in sscanf resulted to writing of multiple bytes (notice that '%d' is for 'int') which inturn cleared the adjacent bytes of ram at address &var1_1byte.

thus, var1_1byte, var2_1byte got modified. checking the .map file i confirmed the error and realized the mistake.

i used '%d' instead of '%c' so that ascii value in buffer is converted to integer (actually wanted to convert to hex).

Ignorant. (Sic).

luckily i could trace the error in not more than 5 minutes. a newbie may have consumed more time hence thought of bringing to the notice of others.

Parents
  • luckily i could trace the error in not more than 5 minutes.
    You appear somewhat proud of that achievement. Don't be. Any coding style which allows this to consume as much as 5 seconds has to be considered fatally flawed, IMHO.

    This type of silly coding mistake is what compiler warnings exist to tell you about. If you weren't warned by your compiler about this construct long before it was ever executed, you have the warning level set considerably too far down for your own good.

    a newbie may have consumed more time hence thought of bringing to the notice of others.

    Which is why newbies should always have their compilers' warning level cranked way up high.

Reply
  • luckily i could trace the error in not more than 5 minutes.
    You appear somewhat proud of that achievement. Don't be. Any coding style which allows this to consume as much as 5 seconds has to be considered fatally flawed, IMHO.

    This type of silly coding mistake is what compiler warnings exist to tell you about. If you weren't warned by your compiler about this construct long before it was ever executed, you have the warning level set considerably too far down for your own good.

    a newbie may have consumed more time hence thought of bringing to the notice of others.

    Which is why newbies should always have their compilers' warning level cranked way up high.

Children