[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCH 22/22] nolibc: Clear a -Wstringop-overflow warning for strncpy


  • To: <minios-devel@xxxxxxxxxxxxxxxxxxxx>, <simon.kuenzer@xxxxxxxxx>
  • From: Wei Chen <wei.chen@xxxxxxx>
  • Date: Thu, 8 Nov 2018 09:51:53 +0000
  • Authentication-results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; lists.xenproject.org; dkim=none (message not signed) header.d=none;lists.xenproject.org; dmarc=bestguesspass action=none header.from=arm.com;
  • Cc: Kaly.Xin@xxxxxxx, nd@xxxxxxx, wei.chen@xxxxxxx
  • Delivery-date: Thu, 08 Nov 2018 09:53:09 +0000
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>
  • Nodisclaimer: True
  • Spamdiagnosticmetadata: NSPM
  • Spamdiagnosticoutput: 1:99

The strncpy needs a signed integer for 3rd parameter, but the SIZE_MAX
is unsigned integer. We will get following error:
/lib/nolibc/string.c:155:9: warning: ‘strncpy’: specified size
18446744073709551615 exceeds maximum object size 9223372036854775807
[-Wstringop-overflow=]
  return strncpy(dst, src, SIZE_MAX);
         ^
Using SSIZE_MAX to replace SIZE_MAX to fix this warning.

Signed-off-by: Wei Chen <wei.chen@xxxxxxx>
---
 lib/nolibc/string.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/nolibc/string.c b/lib/nolibc/string.c
index 6f853ba..fa450c9 100644
--- a/lib/nolibc/string.c
+++ b/lib/nolibc/string.c
@@ -152,7 +152,7 @@ char *strncpy(char *dst, const char *src, size_t len)
 
 char *strcpy(char *dst, const char *src)
 {
-       return strncpy(dst, src, SIZE_MAX);
+       return strncpy(dst, src, SSIZE_MAX);
 }
 
 int strncmp(const char *str1, const char *str2, size_t len)
-- 
2.17.1


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.