This is the mail archive of the glibc-bugs-regex@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug regex/6722] sscanf bug when parsing lines from /proc/net/tcp


------- Additional Comments From halesh dot s at gmail dot com  2008-07-08 07:46 -------
(In reply to comment #4)
> Well, locaddr and remaddr are 32-bit ints, but locport and remport are not;
> the testcase doesn't only violate aliasing rules, but with the 32-bit write
> to 16-bit memory locations also clobbers unrelated memory on the stack.
> Either use %8x:%4hx and kill the bogus casts, or you need to assign to
> int/unsigned int temporaries and copy to the short vars afterwards.
> 


We can avoide cloberring of 16 bit hex vairables by using %hx, How to avoide 
the same when using u_int8_t variables.
We cant use %hx for u_int8_t as its only upto short int - 16 bits.

Please check the below testcase

#include <stdio.h>
#include <sys/types.h>

int main()
{

        int cur = 123;
        u_int8_t var1;
        u_int8_t var2;

        scanf("%x", &var1);
        scanf("%x", &var2);

        printf("var1 = %x\n", var1);
        printf("var2 = %x\n", var2);

        printf("cur = %d\n", cur);
}

O/P is...
1 
2 
var1 = 0  **
var2 = 2
cur = 0  **

How to avoide the clobbering while using of 8 bit hex??
Any idea abt this??

-- 


http://sourceware.org/bugzilla/show_bug.cgi?id=6722

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]