@@ -261,3 +261,52 @@ options.
261
261
If you have a function that takes an array parameter, but without an associated
262
262
size parameter, you can also use the ` --treat-pointer-as-array <parameter-name> `
263
263
option.
264
+
265
+ ---
266
+
267
+ If you want to non-deterministically initialise a pointer
268
+ as a C string (character array with last element ` '\0' ` )
269
+ then you can do that like this:
270
+
271
+ ``` C
272
+ // nondet_string.c
273
+
274
+ #include < assert.h>
275
+
276
+ void function (char * pointer, int size)
277
+ {
278
+ assert(pointer[ size-1] == '\0');
279
+ }
280
+ ```
281
+
282
+ Then call the following:
283
+
284
+ ```
285
+ $ goto-cc -o nondet_string.gb nondet_string.c
286
+ $ goto-harness \
287
+ --harness-function-name harness \
288
+ --harness-type call-function \
289
+ --function function \
290
+ --treat-pointer-as-cstring pointer \
291
+ --associated-array-size pointer: size \
292
+ nondet_string.gb nondet_string-mod.gb
293
+ $ cbmc --function harness nondet_string-mod.gb
294
+ ```
295
+
296
+ Note that C strings are supported by the same mechanism
297
+ behind the non-deterministic initialisation of pointers
298
+ and arrays, so the same command line arguments apply, in
299
+ particular `--associated-array-size`.
300
+
301
+ This will result in:
302
+
303
+ ```
304
+ [ ...]
305
+
306
+ ** Results:
307
+ main.c function function
308
+ [ function.assertion.1] line 5 assertion pointer[ size-1] == '\0': SUCCESS
309
+
310
+ ** 0 of 1 failed (1 iterations)
311
+ VERIFICATION SUCCESSFUL
312
+ ```
0 commit comments