1
1
/*------------------------------------------------------------------
2
2
* test_snprintf_s
3
3
*
4
- *
5
4
*------------------------------------------------------------------
6
5
*/
7
6
@@ -33,7 +32,7 @@ int test_snprintf_s (void)
33
32
34
33
/*--------------------------------------------------*/
35
34
36
- rc = snprintf_s (str1 , LEN , "%s" , NULL );
35
+ rc = snprintf_s (str1 , LEN , NULL , NULL );
37
36
if (rc != ESNULLP ) {
38
37
debug_printf ("%s %u Error rc=%u \n" ,
39
38
__FUNCTION__ , __LINE__ , rc );
@@ -64,7 +63,7 @@ int test_snprintf_s (void)
64
63
strcpy (str2 , "keep it simple" );
65
64
66
65
rc = snprintf_s (str1 , 1 , "%s" , str2 );
67
- if (rc != ESUNTERM ) {
66
+ if (rc != 14 ) {
68
67
debug_printf ("%s %u Error rc=%u \n" ,
69
68
__FUNCTION__ , __LINE__ , rc );
70
69
errs ++ ;
@@ -82,42 +81,37 @@ int test_snprintf_s (void)
82
81
strcpy (str2 , "keep it simple" );
83
82
84
83
rc = snprintf_s (str1 , 2 , "%s" , str2 );
85
- if (rc != ESUNTERM ) {
84
+ if (rc != 14 ) {
86
85
debug_printf ("%s %u Error rc=%u \n" ,
87
86
__FUNCTION__ , __LINE__ , rc );
88
87
errs ++ ;
89
88
}
90
89
91
- if (str1 [0 ] != '\0' ) {
92
- debug_printf ("%s %u Expected null \n" ,
93
- __FUNCTION__ , __LINE__ );
94
- errs ++ ;
95
- }
96
-
97
90
/*--------------------------------------------------*/
98
91
99
- strcpy (& str1 [ 0 ] , "aaaaaaaaaa" );
100
- strcpy (& str2 [ 0 ] , "keep it simple" );
92
+ strcpy (str1 , "aaaaaaaaaa" );
93
+ strcpy (str2 , "keep it simple" );
101
94
102
95
len1 = strlen (str1 );
103
96
len2 = strlen (str2 );
104
97
105
98
rc = snprintf_s (str1 , 50 , "%s" , str2 );
106
- if (rc != EOK ) {
99
+ if (rc != len2 ) {
107
100
debug_printf ("%s %u Error rc=%u \n" ,
108
101
__FUNCTION__ , __LINE__ , rc );
109
102
errs ++ ;
110
103
}
111
104
112
105
len3 = strlen (str1 );
113
- if (len3 != ( len1 + len2 ) ) {
106
+ if (len3 != len2 ) {
114
107
debug_printf ("%s %u lengths wrong: %u %u %u \n" ,
115
108
__FUNCTION__ , __LINE__ , len1 , len2 , len3 );
116
109
errs ++ ;
117
110
}
118
111
119
112
/*--------------------------------------------------*/
120
113
114
+ str1 [0 ] = '\0' ;
121
115
strcpy (str2 , "keep it simple" );
122
116
123
117
rc = snprintf_s (str1 , 5 , "%s" , str2 );
@@ -140,27 +134,22 @@ int test_snprintf_s (void)
140
134
strcpy (str2 , "keep it simple" );
141
135
142
136
rc = snprintf_s (str1 , 2 , "%s" , str2 );
143
- if (rc != ESNOSPC ) {
137
+ if (rc != 14 ) {
144
138
debug_printf ("%s %u Error rc=%u \n" ,
145
139
__FUNCTION__ , __LINE__ , rc );
146
140
errs ++ ;
147
141
}
148
142
149
- if (str1 [0 ] != '\0' ) {
150
- debug_printf ("%s %u Expected null \n" ,
151
- __FUNCTION__ , __LINE__ );
152
- errs ++ ;
153
- }
154
-
155
143
/*--------------------------------------------------*/
156
144
157
145
str1 [0 ] = '\0' ;
158
146
strcpy (str2 , "keep it simple" );
159
147
160
148
rc = snprintf_s (str1 , 20 , "%s" , str2 );
161
- if (rc != EOK ) {
149
+ if (rc <= 0 ) {
162
150
debug_printf ("%s %u Error rc=%u \n" ,
163
151
__FUNCTION__ , __LINE__ , rc );
152
+ errs ++ ;
164
153
}
165
154
166
155
ind = strcmp (str1 , str2 );
@@ -176,7 +165,7 @@ int test_snprintf_s (void)
176
165
str2 [0 ] = '\0' ;
177
166
178
167
rc = snprintf_s (str1 , LEN , "%s" , str2 );
179
- if (rc != EOK ) {
168
+ if (rc != 0 ) {
180
169
debug_printf ("%s %u Error rc=%u \n" ,
181
170
__FUNCTION__ , __LINE__ , rc );
182
171
errs ++ ;
@@ -194,7 +183,7 @@ int test_snprintf_s (void)
194
183
strcpy (str2 , "keep it simple" );
195
184
196
185
rc = snprintf_s (str1 , LEN , "%s" , str2 );
197
- if (rc != EOK ) {
186
+ if (rc <= 0 ) {
198
187
debug_printf ("%s %u Error rc=%u \n" ,
199
188
__FUNCTION__ , __LINE__ , rc );
200
189
errs ++ ;
@@ -213,13 +202,13 @@ int test_snprintf_s (void)
213
202
strcpy (str2 , "keep it simple" );
214
203
215
204
rc = snprintf_s (str1 , LEN , "%s" , str2 );
216
- if (rc != EOK ) {
205
+ if (rc <= 0 ) {
217
206
debug_printf ("%s %u Error rc=%u \n" ,
218
207
__FUNCTION__ , __LINE__ , rc );
219
208
errs ++ ;
220
209
}
221
210
222
- ind = strcmp (str1 , "qqweqqkeep it simple" );
211
+ ind = strcmp (str1 , "keep it simple" );
223
212
if (ind != 0 ) {
224
213
debug_printf ("%s %u Error -%s- \n" ,
225
214
__FUNCTION__ , __LINE__ , str1 );
@@ -232,7 +221,7 @@ int test_snprintf_s (void)
232
221
strcpy (str2 , "keep it simple" );
233
222
234
223
rc = snprintf_s (str1 , 12 , "%s" , str2 );
235
- if (rc != ESNOSPC ) {
224
+ if (rc != 14 ) { /* sic! unsafe */
236
225
debug_printf ("%s %u Error rc=%u \n" ,
237
226
__FUNCTION__ , __LINE__ , rc );
238
227
errs ++ ;
@@ -244,13 +233,13 @@ int test_snprintf_s (void)
244
233
strcpy (str2 , "keep it simple" );
245
234
246
235
rc = snprintf_s (str1 , 52 , "%s" , str2 );
247
- if (rc != EOK ) {
236
+ if (rc <= 0 ) {
248
237
debug_printf ("%s %u Error rc=%u \n" ,
249
238
__FUNCTION__ , __LINE__ , rc );
250
239
errs ++ ;
251
240
}
252
241
253
- ind = strcmp (str1 , "1234keep it simple" );
242
+ ind = strcmp (str1 , "keep it simple" );
254
243
if (ind != 0 ) {
255
244
debug_printf ("%s %u Error -%s- \n" ,
256
245
__FUNCTION__ , __LINE__ , str1 );
@@ -262,32 +251,26 @@ int test_snprintf_s (void)
262
251
strcpy (str1 , "12345678901234567890" );
263
252
264
253
rc = snprintf_s (str1 , 8 , "%s" , & str1 [7 ]);
265
- if (rc != ESOVRLP ) {
254
+ if (rc != 13 ) {
266
255
debug_printf ("%s %u Error rc=%u \n" ,
267
256
__FUNCTION__ , __LINE__ , rc );
268
257
errs ++ ;
269
258
}
270
259
271
- if (str1 [0 ] != '\0' ) {
272
- debug_printf ("%s %u Expected null \n" ,
273
- __FUNCTION__ , __LINE__ );
274
- errs ++ ;
275
- }
276
-
277
260
/*--------------------------------------------------*/
278
261
279
262
strcpy (str1 , "123456789" );
280
263
281
264
rc = snprintf_s (str1 , 9 , "%s" , & str1 [8 ]);
282
- if (rc != ESOVRLP ) {
265
+ if (rc != 1 ) { /* overlapping allowed */
283
266
debug_printf ("%s %u Error rc=%u \n" ,
284
267
__FUNCTION__ , __LINE__ , rc );
285
268
errs ++ ;
286
269
}
287
-
288
- if (str1 [ 0 ] != '\0' ) {
289
- debug_printf ("%s %u Expected null \n" ,
290
- __FUNCTION__ , __LINE__ );
270
+ ind = strcmp ( str1 , "9" );
271
+ if (ind != 0 ) {
272
+ debug_printf ("%s %u Error -%s- \n" ,
273
+ __FUNCTION__ , __LINE__ , str1 );
291
274
errs ++ ;
292
275
}
293
276
@@ -297,13 +280,13 @@ int test_snprintf_s (void)
297
280
strcpy (str1 , "keep it simple" );
298
281
299
282
rc = snprintf_s (str2 , 31 , "%s" , & str1 [0 ]);
300
- if (rc != EOK ) {
283
+ if (rc <= 0 ) {
301
284
debug_printf ("%s %u Error rc=%u \n" ,
302
285
__FUNCTION__ , __LINE__ , rc );
303
286
errs ++ ;
304
287
}
305
288
306
- ind = strcmp (str2 , "123keep it simple" );
289
+ ind = strcmp (str2 , "keep it simple" );
307
290
if (ind != 0 ) {
308
291
debug_printf ("%s %u Error -%s- \n" ,
309
292
__FUNCTION__ , __LINE__ , str1 );
@@ -316,13 +299,13 @@ int test_snprintf_s (void)
316
299
strcpy (str1 , "56789" );
317
300
318
301
rc = snprintf_s (str2 , 10 , "%s" , str1 );
319
- if (rc != EOK ) {
302
+ if (rc <= 0 ) {
320
303
debug_printf ("%s %u Error rc=%u \n" ,
321
304
__FUNCTION__ , __LINE__ , rc );
322
305
errs ++ ;
323
306
}
324
307
325
- ind = strcmp (str2 , "123456789 " );
308
+ ind = strcmp (str2 , "56789 " );
326
309
if (ind != 0 ) {
327
310
debug_printf ("%s %u Error -%s- \n" ,
328
311
__FUNCTION__ , __LINE__ , str1 );
0 commit comments