2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
13 * Copyright 2017 Joyent, Inc.
17 * Regression test for illumos #6961. We mistakenly zeroed out a character that
18 * we shouldn't have when dealing with a 64-bit libc.
27 print_diff(char *test
, char *correct
, char *wrong
)
30 printf("test failed: received incorrect octal for case %s\n", test
);
31 for (i
= 0; i
< 32; i
++) {
32 printf("byte %d: expected 0x%x, found 0x%x\n", i
, correct
[i
],
44 char octal0
[] = { 'r', 'r', 'r', 'r', '1', '7', '7', '7', '7', '7', '7',
45 '7', '7', '7', '7', '7', '7', '7', '7', '7', '7', '7', '7', '7',
46 '7', '7', '\0', 'r', 'r', 'r', 'r', 'r', 'r' };
48 char decimal0
[] = { 'r', 'r', 'r', 'r', '-', '1', '\0', 'r', 'r', 'r',
49 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r',
50 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r' };
52 char hex0
[] = { 'r', 'r', 'r', 'r', 'f', 'f', 'f', 'f', 'f', 'f',
53 'f', 'f', 'f', 'f', 'f', 'f', 'f', 'f', 'f', 'f', '\0', 'r', 'r',
54 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r' };
57 char octal1
[] = { 'r', 'r', 'r', 'r', '5', '2', '\0', 'r', 'r', 'r',
58 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r',
59 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r' };
62 char decimal1
[] = { 'r', 'r', 'r', 'r', '4', '2', '\0', 'r', 'r', 'r',
63 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r',
64 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r' };
67 char hex1
[] = { 'r', 'r', 'r', 'r', '2', 'a', '\0', 'r', 'r', 'r', 'r',
68 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r',
69 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r' };
72 (void) memset(buf
, 'r', sizeof (buf
));
73 (void) snprintf(buf
+ 4, sizeof (buf
), "%lo", ~0L);
74 if (bcmp(octal0
, buf
, sizeof (buf
)) != 0) {
75 print_diff("~0 in Octal", octal0
, buf
);
79 (void) memset(buf
, 'r', sizeof (buf
));
80 (void) snprintf(buf
+ 4, sizeof (buf
), "%lo", 42L);
81 if (bcmp(octal1
, buf
, sizeof (buf
)) != 0) {
82 print_diff("42 in Octal", octal1
, buf
);
86 (void) memset(buf
, 'r', sizeof (buf
));
87 (void) snprintf(buf
+ 4, sizeof (buf
), "%ld", ~0L);
88 if (bcmp(decimal0
, buf
, sizeof (buf
)) != 0) {
89 print_diff("~0 in Decimal", decimal0
, buf
);
93 (void) memset(buf
, 'r', sizeof (buf
));
94 (void) snprintf(buf
+ 4, sizeof (buf
), "%ld", 42L);
95 if (bcmp(decimal1
, buf
, sizeof (buf
)) != 0) {
96 print_diff("42 in Decimal", decimal1
, buf
);
100 (void) memset(buf
, 'r', sizeof (buf
));
101 (void) snprintf(buf
+ 4, sizeof (buf
), "%lx", ~0L);
102 if (bcmp(hex0
, buf
, sizeof (buf
)) != 0) {
103 print_diff("~0 in Hex", hex0
, buf
);
107 (void) memset(buf
, 'r', sizeof (buf
));
108 (void) snprintf(buf
+ 4, sizeof (buf
), "%lx", 42L);
109 if (bcmp(hex1
, buf
, sizeof (buf
)) != 0) {
110 print_diff("42 in Hex", hex1
, buf
);