1 /* 2 bug-2452.c 3 */ 4 5 #include <stdbool.h> 6 #include <testfwk.h> 7 8 typedef struct 9 { 10 unsigned char byte[5]; 11 } value_t; 12 13 static void output_digit(unsigned char n)14output_digit (unsigned char n) 15 { 16 ASSERT(n == 9); 17 } 18 19 static void calculate_digit(value_t * value)20calculate_digit (value_t *value) 21 { 22 value->byte[4] = 9; 23 } 24 25 int xprint_format(const char * format)26xprint_format (const char *format) 27 { 28 value_t value; 29 bool lsd; 30 int i; 31 32 unsigned char length; 33 34 while( *format++ ) 35 { 36 unsigned char store[6]; 37 unsigned char *pstore = &store[5]; 38 39 format++; 40 41 42 lsd = 1; 43 i = 1; 44 do { 45 value.byte[4] = 0; 46 47 calculate_digit(&value); 48 49 if (!lsd) 50 { 51 *pstore = (value.byte[4] << 4) | (value.byte[4] >> 4) | *pstore; 52 pstore--; 53 } 54 else 55 { 56 *pstore = value.byte[4]; 57 } 58 59 lsd = !lsd; 60 } while( i-- ); 61 62 length = 2; 63 64 ASSERT(lsd); 65 66 while( length-- ) 67 { 68 lsd = !lsd; 69 if (!lsd) 70 { 71 pstore++; 72 value.byte[4] = *pstore >> 4; 73 } 74 else 75 { 76 value.byte[4] = *pstore & 0x0F; 77 } 78 79 output_digit( value.byte[4]); 80 } 81 } 82 83 return 0; 84 } 85 86 void test_xprintf(void)87test_xprintf (void) 88 { 89 xprint_format ("%d"); 90 } 91 92