Gamestudio Links
Zorro Links
Newest Posts
Increasing Number Animation
by gamers. 02/19/20 07:16
Behaviour of user-defined bars
by JamesHH. 02/18/20 18:41
AUM Magazine
Latest Screens
The Space Between
Pogostuck: Rage With Your Friends
Worst Case Z
AckCon'18 - Lotter vs the World 2 - Preview Release
Who's Online Now
8 registered members (Zheka, gamers, txesmi, 3run, Dico, RealSerious3D, jenGs, tnktnns), 1,154 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
DebraSteed, Ricard, Apollo1, ziphnor, thomasprv
18377 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Add safety string functions ("strcpy_s", etc.) #478933
01/21/20 11:56
01/21/20 11:56
Joined: Feb 2017
Posts: 858
Chicago
AndrewAMD Offline OP
User
AndrewAMD  Offline OP
User

Joined: Feb 2017
Posts: 858
Chicago
jcl,

Can the following string/memory functions be added to Zorro's Lite-C library?
Code
errno_t strcpy_s( char *dest, rsize_t dest_size, const char *src);
int sprintf_s(char *buffer,  size_t sizeOfBuffer,  const char *format,  ...);
errno_t strcat_s(char *strDestination, size_t numberOfElements, const char *strSource);
errno_t memcpy_s(void *dest,   size_t destSize,   const void *src,   size_t count);
Thanks,
Andrew

Re: Add safety string functions ("strcpy_s", etc.) [Re: AndrewAMD] #478944
01/22/20 13:36
01/22/20 13:36
Joined: Jul 2000
Posts: 27,109
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,109
Frankfurt
Yes, we can add them to stdio.h.

Re: Add safety string functions ("strcpy_s", etc.) [Re: AndrewAMD] #478946
01/22/20 15:25
01/22/20 15:25
Joined: Feb 2017
Posts: 858
Chicago
AndrewAMD Offline OP
User
AndrewAMD  Offline OP
User

Joined: Feb 2017
Posts: 858
Chicago
Thank you!

Re: Add safety string functions ("strcpy_s", etc.) [Re: AndrewAMD] #478955
01/25/20 16:32
01/25/20 16:32
Joined: Oct 2017
Posts: 4
Munich
K
kalmar Offline
Guest
kalmar  Offline
Guest
K

Joined: Oct 2017
Posts: 4
Munich
Hi, Andrew,

Could you please explain a bit the idea behind?

Thank you!

Re: Add safety string functions ("strcpy_s", etc.) [Re: AndrewAMD] #478956
01/25/20 16:43
01/25/20 16:43
Joined: Feb 2017
Posts: 858
Chicago
AndrewAMD Offline OP
User
AndrewAMD  Offline OP
User

Joined: Feb 2017
Posts: 858
Chicago
These functions require the programmer to define the sizes of the buffer being written to.

If the function detects that the output buffer is too small, then it will, depending on the settings/implementation:
* Halt the program and clearly explain what the problem is.
* Throw an exception (not supported in Lite-C).
* Or simply return an error, and then the programmer can handle it manually without aborting the program.
* A callback function can be used in the event of any of the above.

In all cases, the bad buffer write does not occur.

Interestingly, the git project has banned all uses of strcpy(), strcat(), and sprintf() using a header:
https://github.com/git/git/blob/master/banned.h

Background: I just had to scrub one of my trading systems clean because it was crashing under mysterious circumstances. After much work, the bug disappeared for reasons unknown.

Murphy's Law: Things that can go wrong will go wrong. It's better to try to get things right the first time around.

[Linked Image]

Attached Files
developers_projects.jpg (608 downloads)

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1