From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A64543C067 for ; Fri, 6 Feb 2026 19:11:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770405096; cv=none; b=eR+kNVzE2XLFHMwM7z4xO+IgIHBeq9UMLBJ7cf3ItCZ8hspQWWRd+xcPgGox1iXKsuJLUDkPkMUBMF5CBmHX/9xBl4BVBllKkvFYN+DnmU66jg6o7DnyuEa2CrHnS1U+kJl74I1N3uQJi6tc9I4SN8Gi46j759amDVN1D1Bwd5g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770405096; c=relaxed/simple; bh=4oivlfgekHb61HoaU5Vjzu0HzE9LAEnZS5dWZaEMNRM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Hf2XcLgM6cETIGfxL2tMPSwTGo3z0GuV0/ykEpofW9vqAnsUSomf9nCXDlPIH7VYz7Lb28mqGIuHIyZl1AiG6WQx9T660O/YD5j8GbjV62AhsWcsLHix3Wu1QnWQizo1LsnMVYgSYDyzk4WUcqPLy79WQ9+wtp/QimeJtA9eI/Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=HHtZ0BCi; arc=none smtp.client-ip=209.85.221.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HHtZ0BCi" Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-4359a316d89so2025001f8f.0 for ; Fri, 06 Feb 2026 11:11:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770405094; x=1771009894; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PyT+OqQ4mgjyjy7LfQK7LyTWgLn3d8IzTxwU2qh9KRk=; b=HHtZ0BCihte6J+He6MZcuFg0aio52W2LO3h1W6uJkHJFC3bIw9CkQMS2xFRuZWTXEH rVqH+/V2pjZPmK6YG+ESXIPH9WG6txlp9nm9lb/6tmvYs67FWoZ8/yyawoDoUTjOCA94 nsxag+x/csB5/ZoBGUO4VHfR0HF+JnEQZUfFoM/fWXyrm1fBANStvTPz/Yuuup7sNqTo 60Tf/MRd5/wSD2PaGFAOHbifMgszKpGGclcR6Yej0NmYw1a5rjeoEALqyhLgm/k/CJ36 dgxfPkFBaTn3zvB31m+hq6b7MzMzD+0VEi9gXJM9iUp2FIuL/qPMsawceRXhc+V87rph BIqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770405094; x=1771009894; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=PyT+OqQ4mgjyjy7LfQK7LyTWgLn3d8IzTxwU2qh9KRk=; b=vfRLTtGLBUepsNUbr8CQtcXjz+Hr67c7OLDSS/+XaZ0pL3Bze8RXFMb54n/J6NIEuS 73b/a1FVK3VI0hCANX3DbciaTkItfI/4Q9S55FRimfgPv2zRHIbtCaFufKALnd1oXeRV /0hSWeYkmgjGBekQmVLfJKkCqfTU9IpwmW+moVgPBAWyLRjhfAcAV7gPs9GKzCKlKGzA 67fPTCjnfSDrjDYHu3eucVAhfDcffzP4hVi2WDx6MWhhmVvCF2iI0X5UZj1reszp7x/4 arWjmJxBDbgcK+cKYnC0RP5if5cCR0FfJcUX7cfpPSHGsy6aCwXheqhSV4CkffljGy/+ 3pQA== X-Forwarded-Encrypted: i=1; AJvYcCVKsu16GNZE6vKkx2iJ+/vb38klyonUECkXswcb75+EhnXGsp32GxHWCpOBnjumIAfjWluPqWNxfHKdjrE=@vger.kernel.org X-Gm-Message-State: AOJu0YzQBfVqIbOqcAKLVIHeNVoKToZAuhMH4j+7L6zVgsqMFzFuRfs/ BJetyCWfuplttWT3VI5PkQGM7BWVO3Ro+faYGNyErLZZpTr53J6mg9aS X-Gm-Gg: AZuq6aKbPUNMuMXqtVnEuOF59aphqhv9Jg3qyI4nDDv6+MlJ8SDrSgiOt59S/CqWEiz CkNC3J5lhEj/l3sOBBwKq56d96u6MLsBGc6XXcJnmpHu2w03AmGAo8F7pe6WHUSI+uVeaCv+/do wOPLprGn44gXNEOh9aWpa7uhXaa7L55SQs2gL0pNi9OoZokuzcCt3ioarmUxxi1bhk3QxbtSkg4 TsucMlkkXEa9uK7WFOg0xuK+kpycwSUMdVZXT8GpEF3XYFHnoOacTj5b3zWr1r3FtG/e227s7Pb LuLgzWmT5pDirxTINO2RTNEkh6jM7HSmJG+XqmznhnGvsELc506Zal1LQaIFKZYHe5iIoIpmMiX 4umcKXbf73TOlQcC6stfOVl08+trwyb2Jwnp8Qdklh6BPy0hciGQgXO8XjPmmlKbwhKPnlDgc+t lJTog1i4AUhlx5BsOwEYFzqi2VRumSLI8HvBWhIOlu/ApmMCgAZU1f5MSJGLnuB0N/Jdvvacss X-Received: by 2002:a05:6000:2086:b0:430:ff0c:3615 with SMTP id ffacd0b85a97d-4362937bdabmr7362952f8f.53.1770405094355; Fri, 06 Feb 2026 11:11:34 -0800 (PST) Received: from snowdrop.snailnet.com (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4362972fb81sm8703681f8f.20.2026.02.06.11.11.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Feb 2026 11:11:34 -0800 (PST) From: david.laight.linux@gmail.com To: Willy Tarreau , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , linux-kernel@vger.kernel.org, Cheng Li Cc: David Laight Subject: [PATCH v2 next 09/11] selftests/nolibc: Improve reporting of vfprintf() errors Date: Fri, 6 Feb 2026 19:11:19 +0000 Message-Id: <20260206191121.3602-10-david.laight.linux@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260206191121.3602-1-david.laight.linux@gmail.com> References: <20260206191121.3602-1-david.laight.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: David Laight Check the string matches before checking the returned length. Only print the string once when it matches. Normally the length is that of the expected string, make it easier to write tests by treating a length of zero as being that of the expected output. Additionally check that nothing beyond the end is written. This also correctly returns 1 (the number of errors) when strcmp() fails rather than the return value from strncmp() which is the signed difference between the mismatching characters. Signed-off-by: David Laight --- Changes for v2: - Formally patch 5, otherwise unchanged. tools/testing/selftests/nolibc/nolibc-test.c | 27 ++++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 3c5a226dad3a..9378a1f26c34 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -1567,28 +1567,45 @@ int run_stdlib(int min, int max) static int expect_vfprintf(int llen, int c, const char *expected, const char *fmt, ...) { + unsigned int i; char buf[100]; va_list args; ssize_t w; int ret; + for (i = 0; i < sizeof(buf); i++) + buf[i] = i; va_start(args, fmt); - /* Only allow writing 21 bytes, to test truncation */ + /* Only allow writing 20 bytes, to test truncation */ w = vsnprintf(buf, 21, fmt, args); va_end(args); + llen += printf(" \"%s\"", buf); + ret = strcmp(expected, buf); + if (ret) { + llen += printf(" should be \"%s\"", expected); + result(llen, FAIL); + return 1; + } + if (!c) + c = strlen(expected); if (w != c) { llen += printf(" written(%d) != %d", (int)w, c); result(llen, FAIL); return 1; } - llen += printf(" \"%s\" = \"%s\"", expected, buf); - ret = strncmp(expected, buf, c); + for (i = c + 1; i < sizeof(buf); i++) { + if (buf[i] - i) { + llen += printf(" overwrote buf[%d] with 0x%x", i, buf[i]); + result(llen, FAIL); + return 1; + } + } - result(llen, ret ? FAIL : OK); - return ret; + result(llen, OK); + return 0; } static int test_scanf(void) -- 2.39.5