A pitfall of strncpy.

Abstract: When you put the correct arguments of strncpy, there is a case that your char[] buffer may not contain a valid C string anymore. The strncpy function has this unexpected behavior because of the standard specification. It is also mentioned in the ``Writing Solid Code'' as a defect of function design. Actually, Stroustrup's C++ Programming Language book mentioned it, and the book suggests to not to use it. (at page 600 of the third edition.) But it is mentioned in one line comment of a sample code. I think people usually can not realize that except someone have been bitten by this bug like me.


Copyright (C) 2005-2006 Yamauchi, Hitoshi
Most recent update : :