https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115056

--- Comment #7 from Sam James <sjames at gcc dot gnu.org> ---
Isn't there still an uninitialised read?

```
$ valgrind /tmp/foo
[...]
==814922==
1886221359
1
0
0
0
0
0
==814922== Use of uninitialised value of size 8
==814922==    at 0x48F7D3A: _itoa_word (_itoa.c:183)
==814922==    by 0x49029A6: __printf_buffer (vfprintf-process-arg.c:155)
==814922==    by 0x4904BD0: __vfprintf_internal (vfprintf-internal.c:1544)
==814922==    by 0x49C55AE: __printf_chk (printf_chk.c:33)
==814922==    by 0x10938D: main (/tmp/foo.c:16)
==814922==
```

with:
```
#include <string.h>
#include <stdio.h>
typedef union {
        unsigned char as_bytes[64];
        unsigned long long as_chunks[64 / sizeof(unsigned long long)];
} Block;
int main(int argc, char **argv) {
        Block block;
        int i = strlen(argv[0]), j = 0;
        for (; j < i; j++) block.as_bytes[j] = argv[0][j];
        block.as_bytes[j] = 0x01; // I removed this line
        while (++j & 7) block.as_bytes[j] = 0;
        if (j > 56) while (j < 64) block.as_bytes[j++] = 0;
        while (j < 56) block.as_bytes[j++] = 0;
        for (j = 0; j < 8; j++) printf("%d\n", (int)block.as_chunks[j]);
}
```

Reply via email to