Possible problem in helpfile with the "strncpy" function

Beta Testing discussion on mikroPascal 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:28

This is valid for all mP 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)

User avatar
petar.timotijevic
mikroElektronika team
Posts: 1739
Joined: 19 Feb 2014 13:46
Location: Serbia
Contact:

Re: Possible problem in helpfile with the "strncpy" function

#2 Post by petar.timotijevic » 07 May 2015 16:15

Hi Dany,

Thank You for these informations. I will check this and I will forward these informations to our development team.


Best regards,
Peter

Post Reply

Return to “mikroPascal PRO for PIC Beta Testing”