Possible problem in helpfile with the "strncpy" function

Beta Testing discussion on mikroBasic PRO for PIC.
Post Reply
Author
Message
Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Possible problem in helpfile with the "strncpy" function

#1 Post by Dany » 05 May 2015 17:29

This is valid for all mB compilers, not only that for PIC:

In the compiler's help for the "strncpy" function (String library), the "Dst" var parameter is described as a "string" type.
A string should always be terminated by a zero byte, but the function does not always add it, so in certain cases the "Dst" is no proper string because it is unterminated.

This can lead to memory corruption.

This issue was detected here: http://www.mikroe.com/forum/viewtopic.php?f=81&t=64329.
The ansi C definition of StrnCpy is indeed so that the terminating zero is not always added.

Two possibilities exist to remove the inconsistency:
- change the StrnCpy function so that it always add a trailing zero (which makes it different from the "standard" strncpy defintion), or
- Adapt the type of the "Dst" parameter in the helpfile (make it an array of bytes)...

In Janni's replacement libraries (http://www.cobir.com/replibs.htm#Strings) he chose the first option... :D :D
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

Post Reply

Return to “mikroBasic PRO for PIC Beta Testing”