summaryrefslogtreecommitdiff
path: root/support/regression/tests/bug-2897.c
blob: e2b20285084a703ca4b71de16542b689a17a9ead (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
    bug-?.c
*/

#include <testfwk.h>

static const char *expect;

int pc(int c)
{
  ASSERT (c == *expect++);
}

void printhex_le(unsigned char x)
{
  unsigned char n = x>>4;
  if( n>9 ) pc('A'-10+n); else pc('0'+n); // Bug for n == 'a'. Works when >9 is replaced by >=10
  n = x&0xF;
  if( n>9 ) pc('A'-10+n); else pc('0'+n); // Bug for n == 'a'. Works when >9 is replaced by >=10
}

void printhex_leq(unsigned char x)
{
  unsigned char n = x>>4;
  if( n>=10 ) pc('A'-10+n); else pc('0'+n);
  n = x&0xF;
  if( n>=10 ) pc('A'-10+n); else pc('0'+n);
}

void testBug(void)
{
  expect = "01";
  printhex_le (0x01);
  expect = "23";
  printhex_le (0x23);
  expect = "45";
  printhex_le (0x45);
  expect = "56";
  printhex_le (0x56);
  expect = "78";
  printhex_le (0x78);
  expect = "9A";
  printhex_le (0x9a);
  expect = "BC";
  printhex_le (0xbc);
  expect = "DE";
  printhex_le (0xde);

  expect = "10";
  printhex_le (0x10);
  expect = "32";
  printhex_le (0x32);
  expect = "54";
  printhex_le (0x54);
  expect = "65";
  printhex_le (0x65);
  expect = "87";
  printhex_le (0x87);
  expect = "A9";
  printhex_le (0xa9);
  expect = "CB";
  printhex_le (0xcb);
  expect = "ED";
  printhex_le (0xed);

  expect = "01";
  printhex_leq (0x01);
  expect = "23";
  printhex_leq (0x23);
  expect = "45";
  printhex_leq (0x45);
  expect = "56";
  printhex_leq (0x56);
  expect = "78";
  printhex_leq (0x78);
  expect = "9A";
  printhex_leq (0x9a);
  expect = "BC";
  printhex_leq (0xbc);
  expect = "DE";
  printhex_leq (0xde);

  expect = "10";
  printhex_leq (0x10);
  expect = "32";
  printhex_leq (0x32);
  expect = "54";
  printhex_leq (0x54);
  expect = "65";
  printhex_leq (0x65);
  expect = "87";
  printhex_leq (0x87);
  expect = "A9";
  printhex_leq (0xa9);
  expect = "CB";
  printhex_leq (0xcb);
  expect = "ED";
  printhex_leq (0xed);
}