examples: Fix size calculations of NULL-terminated strings
The C language treats character literal as numbers, which means '\0' is
a number just like 1234 for example. So sizeof('\0') gives us the value
of sizeof(int) which is 4 instead of 1. Fix this by using 1 as the size
of the null characters. It is common in C code to directly use the value
1 when converting between string lengths and buffer sizes, as such
conversions are very common/well-known.
Note: In C++, the size of a character literal evaluates to 1, unlike in
C.
Signed-off-by:
Lingkai Dong <lingkai.dong@arm.com>
Loading
Please register or sign in to comment