FS#10080 - Use strlcpy for string copies and get completely rid of strncpy

Attached to Project: Rockbox
Opened by Nils Wallménius (nls) - Tuesday, 31 March 2009, 16:58 GMT
Last edited by Nils Wallménius (nls) - Tuesday, 14 July 2009, 14:04 GMT
Task Type Patches
Category Operating System/Drivers
Status Closed
Assigned To No-one
Operating System All players
Severity Low
Priority Normal
Reported Version Daily build (which?)
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No


This patch removes strncpy from rockbox and introduces the strlcpy function instead. Most uses of strncpy have been changed to use strlcpy and a few to use memcpy.

the differences between strlcpy and strncpy is that strlcpy guarantees null termination of the copied string while strncpy does not and that strlcpy does not zero pad the rest of the buffer.

This means that copying short strings into large buffers should be a lot faster and that there is no need to guard for the case that the string is truncated and strncpy would not have null terminated it.

This patch touches a lot of files and while i have gone over the changes several times and tested on both gigabeast and c200 and sims there are some things i can't or didn't test so i would appreciate review and testing :)
This task depends upon

Closed by  Nils Wallménius (nls)
Tuesday, 14 July 2009, 14:04 GMT
Reason for closing:  Accepted
Additional comments about closing:  comitted
Comment by Nils Wallménius (nls) - Wednesday, 01 April 2009, 15:11 GMT
updated patch, replaced one call to strncpy with memcpy instead of strlcpy in fat.c (thanks to amiconn for noticing)
Comment by Nils Wallménius (nls) - Thursday, 02 April 2009, 21:35 GMT
fix a mistake in keybox
Comment by Alex Bennee (ajb) - Tuesday, 21 April 2009, 09:00 GMT
Looks good to me. FWIW applying this patch made a whole load of Valgrind warnings I was chasing go away with a m4a file I was debugging. No idea why though :-(
Comment by Alex Bennee (ajb) - Thursday, 04 June 2009, 14:02 GMT
Is anything happening with this patch or has it been rejected?
Comment by Nils Wallménius (nls) - Friday, 05 June 2009, 09:27 GMT
I have been quite busy with exams but i plan to commit this after we release 3.3 which should be in a few weeks.
Any testing is of course very welcome.
Comment by Nils Wallménius (nls) - Saturday, 06 June 2009, 15:48 GMT
Comment by Nils Wallménius (nls) - Tuesday, 14 July 2009, 12:40 GMT
resync, moved strncpy to the pluginlib to allow imported plugin code to use it and revert the changes to doom