[PATCH app-xscope] Use strncpy rather than strlcpy as it is not available on Linux
Alan Coopersmith
alan.coopersmith at oracle.com
Wed Jun 9 16:10:02 PDT 2010
Gaetan Nadon wrote:
> Because it is available on other platforms, it only fails on Linux.
*sigh* is GNU libc ever going to get with the program?
> strncpy should be safe enough in this situation where a constant is copied.
> The xserver private impl of strlcpy is not available to apps.
>
> Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
> ---
> scope.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/scope.c b/scope.c
> index e33c9d9..758fd19 100644
> --- a/scope.c
> +++ b/scope.c
> @@ -337,7 +337,7 @@ ReadCommands (void)
> printf ("> ");
> if (!fgets (line, sizeof line, stdin)) {
> if(feof(stdin)) {
> - strlcpy(line, "quit", sizeof(line));
> + strncpy(line, "quit", sizeof(line));
> } else {
> printf("Error: %s\n", strerror(errno));
> break;
Yeah, since line[1024] is always bigger than "quit" strncpy is safe.
(So is strcpy for that matter, and it wouldn't write 1019 unnecessary bytes
like strncpy, but you can only quit once, so performance isn't important here.)
Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
--
-Alan Coopersmith- alan.coopersmith at oracle.com
Oracle Solaris Platform Engineering: X Window System
More information about the xorg-devel
mailing list