8
/* Call with a string buffer of at least ref_len+1 chars. */
10
my_itoa_check(register unsigned int i, char out_str[], char *ref_str, size_t ref_len)
12
register char *out_ptr = out_str + ref_len;
13
register char *ref_ptr = ref_str + ref_len-1;
18
*out_ptr = i % 10 + 0x30;
21
if (DEBUGHACK) printf("!%c! !%c!\n", *out_ptr, *ref_ptr);
22
if ( *ref_ptr-- != *out_ptr-- ) {
23
if (DEBUGHACK) printf("NOT SAME: '%c' '%c'\n", out_ptr[1], ref_ptr[1]);
28
if (DEBUGHACK) printf("!!! ref_str='%p' ref_ptr='%p' out_str='%p' out_ptr='%p\n'", ref_str, ref_ptr, out_str, out_ptr);
29
if ( (*ref_ptr != *out_ptr) || (ref_str != ref_ptr) )
31
if (DEBUGHACK) printf("NOT SAME: '%c' '%c'\n", out_ptr[1], ref_ptr[1]);
39
my_integer_string_equality_check(register unsigned int i, char *ref_str, size_t ref_len)
41
register char *ref_ptr = ref_str + ref_len-1;
45
test_char = i % 10 + 0x30;
48
if (DEBUGHACK) printf("!%c! !%c!\n", test_char, *ref_ptr);
49
if ( *ref_ptr-- != test_char ) {
50
if (DEBUGHACK) printf("NOT SAME: '%c' '%c'\n", test_char, ref_ptr[1]);
55
if (DEBUGHACK) printf("!!! ref_str='%p' ref_ptr='%p' test_char='%c' ref-char='%c'\n", ref_str, ref_ptr, test_char, *ref_ptr);
56
if ( (*ref_ptr != test_char) || (ref_str != ref_ptr) )
58
if (DEBUGHACK) printf("NOT SAME: '%c' '%c'\n", test_char, ref_ptr[1]);
66
main(int argc, char** argv) {
67
unsigned int i = 1234;
68
unsigned int in_len = (argc >= 2 ? atoi(argv[1]) : 3);
74
char *str = malloc(in_len+1);
76
for (j = 0; j < in_len; ++j) {
77
str[j] = 0x30 + ((j+1) % 10);
84
* o = my_itoa_check(i, outstr, str, in_len);
85
* printf("SAME IF NOT NULL: '%s'\n", o);
88
for (j = 0; j < 100000000; ++j) {
90
i = (!(i % 2) ? ref_num : j % ord);
91
if (DEBUGHACK) printf("%i %i %i %i '%s'\n", j, i, ord, in_len, str);
92
k = my_integer_string_equality_check(i, str, in_len);
94
if (DEBUGHACK) printf("!EUREKA!\n");
99
if (my_integer_string_equality_check(i, str, 3)) {
100
printf("YAY, SAME!\n");
102
printf("NOOOOO, NOT SAME!\n");