Skip to content
Commit f3a5522e authored by Lingkai Dong's avatar Lingkai Dong
Browse files

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's avatarLingkai Dong <lingkai.dong@arm.com>
parent b6416462
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment