diff mbox series

[v2,01/12] libc: Compile with -Wextra

Message ID 20210209014457.108301-2-aik@ozlabs.ru
State Accepted
Headers show
Series Compile with -Wextra | expand

Commit Message

Alexey Kardashevskiy Feb. 9, 2021, 1:44 a.m. UTC
-Wextra enables a bunch of rather useful checks which this fixes.

Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
---
Changes:
v2:
* replaced cast to int with cast to size_t
---
 lib/libc/stdio/vsnprintf.c | 13 +++++++------
 lib/libc/string/memmove.c  |  2 +-
 2 files changed, 8 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/lib/libc/stdio/vsnprintf.c b/lib/libc/stdio/vsnprintf.c
index 21dd04dfe46f..12f30439886d 100644
--- a/lib/libc/stdio/vsnprintf.c
+++ b/lib/libc/stdio/vsnprintf.c
@@ -25,14 +25,14 @@  static int
 print_str_fill(char **buffer, size_t bufsize, char *sizec,
 					const char *str, char c)
 {
-	int i, sizei, len;
+	unsigned i, sizei, len;
 	char *bstart = *buffer;
 
 	sizei = strtoul(sizec, NULL, 10);
 	len = strlen(str);
 	if (sizei > len) {
 		for (i = 0;
-			(i < (sizei - len)) && ((*buffer - bstart) < bufsize);
+			(i < (sizei - len)) && ((size_t)(*buffer - bstart) < bufsize);
 									i++) {
 			**buffer = c;
 			*buffer += 1;
@@ -47,7 +47,7 @@  print_str(char **buffer, size_t bufsize, const char *str)
 	char *bstart = *buffer;
 	size_t i;
 
-	for (i = 0; (i < strlen(str)) && ((*buffer - bstart) < bufsize); i++) {
+	for (i = 0; (i < strlen(str)) && ((size_t)(*buffer - bstart) < bufsize); i++) {
 		**buffer = str[i];
 		*buffer += 1;
 	}
@@ -112,7 +112,7 @@  print_fill(char **buffer, size_t bufsize, char *sizec, unsigned long size,
  	len = print_intlen(size, base) + optlen;
 	if (sizei > len) {
 		for (i = 0;
-			(i < (sizei - len)) && ((*buffer - bstart) < bufsize);
+			(i < (sizei - len)) && ((size_t)(*buffer - bstart) < bufsize);
 									i++) {
 			**buffer = c;
 			*buffer += 1;
@@ -143,7 +143,7 @@  print_format(char **buffer, size_t bufsize, const char *format, void *var)
 		form++;
 	}
 
-	while ((*form != '\0') && ((*buffer - start) < bufsize)) {
+	while ((*form != '\0') && ((size_t)(*buffer - start) < bufsize)) {
 		switch(*form) {
 			case 'u':
 			case 'd':
@@ -163,6 +163,7 @@  print_format(char **buffer, size_t bufsize, const char *format, void *var)
 				break;
 			case 'X':
 				upper = true;
+				/* fallthrough */
 			case 'x':
 				sizec[i] = '\0';
 				value = (unsigned long) var & convert[length_mod];
@@ -260,7 +261,7 @@  vsnprintf(char *buffer, size_t bufsize, const char *format, va_list arg)
 	/* Leave one space for NULL character */
 	bufsize--;
 
-	while(*ptr != '\0' && (buffer - bstart) < bufsize)
+	while(*ptr != '\0' && (size_t)(buffer - bstart) < bufsize)
 	{
 		if(*ptr == '%') {
 			char formstr[20];
diff --git a/lib/libc/string/memmove.c b/lib/libc/string/memmove.c
index 3acf1a973bbe..9d0962847296 100644
--- a/lib/libc/string/memmove.c
+++ b/lib/libc/string/memmove.c
@@ -18,7 +18,7 @@  memmove(void *dest, const void *src, size_t n)
 {
 	char *cdest;
 	const char *csrc;
-	int i;
+	size_t i;
 
 	/* Do the buffers overlap in a bad way? */
 	if (src < dest && src + n >= dest) {