6690 set_nfsv4_ephemeral_mount_to() tries to read AUTOMOUNT_TIMEOUT from defunct...
[unleashed.git] / usr / src / test / libc-tests / tests / printf-6961.c
blob5c60b96425ca0495c149178a7c2ccab85b0cbb2c
1 /*
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
5 * 1.0 of the CDDL.
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.
21 #include <stdio.h>
22 #include <string.h>
23 #include <strings.h>
24 #include <stdlib.h>
26 static void
27 print_diff(char *test, char *correct, char *wrong)
29 int i;
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],
33 wrong[i]);
37 int
38 main(void)
40 int ret = 0;
41 char buf[32];
43 /* ~0L in octal */
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' };
56 /* 42 in octal */
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' };
61 /* 42 in decimal */
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' };
66 /* 42 in hex */
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);
76 ret++;
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);
83 ret++;
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);
90 ret++;
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);
97 ret++;
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);
104 ret++;
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);
111 ret++;
114 return (ret);