19
19
* memccpy
20
20
*/
21
21
22
+ #if defined(sprintf ) || defined(snprintf ) || defined(asprintf )
23
+ # error "sprintf snprintf asprintf macro aliases need to be disabled"
24
+ #endif
25
+
22
26
// prevents Clang from replacing function calls with builtins
23
27
#if 1
24
28
@@ -141,8 +145,9 @@ int nano_tests(void) {
141
145
return __LINE__ ;
142
146
}
143
147
size_t buf_len = T_strlen (buf );
144
- if (buf_len != T_strlen (test_1 ) || buf_len != (size_t )len ) {
145
- printf ("E: %zu != %zu != %d\n" , T_strlen (test_1 ), buf_len , len );
148
+ const size_t test_1_len = T_strlen (test_1 );
149
+ if (buf_len != test_1_len || buf_len != (size_t )len ) {
150
+ printf ("E: %zu != %zu != %d\n" , test_1_len , buf_len , len );
146
151
return __LINE__ ;
147
152
}
148
153
if (pos != pos_1 ) {
@@ -154,6 +159,34 @@ int nano_tests(void) {
154
159
printf ("cmp: %d\n" , cmp );
155
160
return __LINE__ ;
156
161
}
162
+ char append [128 ];
163
+ int snprintf_test = snprintf (append , 20 , "%s" , test_1 );
164
+ if (snprintf_test != (int )test_1_len ) {
165
+ printf ("sprintf_test: %d != %zu\n" , snprintf_test , test_1_len );
166
+ return __LINE__ ;
167
+ }
168
+ int len_2 = snprintf (append , sizeof (append ), "%s" , test_1 );
169
+ if (len_2 != (int )test_1_len ) {
170
+ printf ("E: %d != %zu\n" , len_2 , test_1_len );
171
+ return __LINE__ ;
172
+ }
173
+ char str2 [128 ];
174
+ char * end ;
175
+ end = T_stpcpy (str2 , append );
176
+ end = T_stpcpy (end , "" );
177
+ end = T_stpcpy (end , "foo" );
178
+ if (* end != '\0' ) {
179
+ return __LINE__ ;
180
+ }
181
+ if (end != & str2 [pos_2 ]) {
182
+ printf ("diff %p - %p = %td\n" , end , str2 , (ptrdiff_t )(end - str2 ));
183
+ return __LINE__ ;
184
+ }
185
+ int cmp2 = T_strcmp (str2 , test_2 );
186
+ if (cmp2 != 0 ) {
187
+ printf ("cmp: %d\n" , cmp2 );
188
+ return __LINE__ ;
189
+ }
157
190
return 0 ;
158
191
}
159
192
0 commit comments