From the course: Secure Coding in C

Unlock this course with a free trial

Join today to access over 25,600 courses taught by industry experts.

Minding string functions

Minding string functions - C Tutorial

From the course: Secure Coding in C

Minding string functions

- [Instructor] The thing that makes a string in C as well as in many programming languages is the null character. It terminates the string marking the final character, which isn't output. The null character is ASCII code zero, represented in C as the escape backslash zero character. String literals in C are created with the null character automatically appended. Strings that you cook up yourself must be terminated with the null character. You code the null character. The compiler won't check it for you, if you omit the null character the strings end is undefined, which leads to overflow, an unsafe condition. The C library's C functions rely upon and maintain the null character when manipulating strings. If the code creates a malformed string, one without the null character, the string library functions behavior is unpredictable. Remember that neither the compiler nor do mini string functions monitor overflow. Let me show you an example. In this code, the STRN copy function copies four…

Contents