From patchwork Tue Feb 9 01:44:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Kardashevskiy X-Patchwork-Id: 1438076 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DZQj86fZ9z9sSC for ; Tue, 9 Feb 2021 12:46:20 +1100 (AEDT) Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 4DZQj80F0BzDsZ5 for ; Tue, 9 Feb 2021 12:46:18 +1100 (AEDT) X-Original-To: slof@lists.ozlabs.org Delivered-To: slof@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.ru (client-ip=107.174.27.60; helo=ozlabs.ru; envelope-from=aik@ozlabs.ru; receiver=) Received: from ozlabs.ru (ozlabs.ru [107.174.27.60]) by lists.ozlabs.org (Postfix) with ESMTP id 4DZQhJ2lfLzDvYx for ; Tue, 9 Feb 2021 12:45:36 +1100 (AEDT) Received: from fstn1-p1.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id 82956AE80211; Mon, 8 Feb 2021 20:45:03 -0500 (EST) From: Alexey Kardashevskiy To: slof@lists.ozlabs.org Date: Tue, 9 Feb 2021 12:44:46 +1100 Message-Id: <20210209014457.108301-2-aik@ozlabs.ru> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210209014457.108301-1-aik@ozlabs.ru> References: <20210209014457.108301-1-aik@ozlabs.ru> Subject: [SLOF] [PATCH slof v2 01/12] libc: Compile with -Wextra X-BeenThere: slof@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Patches for https://github.com/aik/SLOF" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "SLOF" -Wextra enables a bunch of rather useful checks which this fixes. Signed-off-by: Alexey Kardashevskiy --- 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 --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) {