From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by sourceware.org (Postfix) with ESMTPS id B4083385829E for ; Fri, 16 Feb 2024 14:20:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B4083385829E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B4083385829E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::102d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708093226; cv=none; b=nq6LpAAMP++iKNrSyB3lxzs0GStQWpTvoVLjQguqgjDj1u2kwZ3B3zUeX8Cv5JZG4+0IbRlqDa05O5U7bHJioXqLhcrh+uQ5+nYQSjLQOF94gVam5kpbS9m5+0QjgkgZEJIm37pX72UNR/9PtIPicLNaXl6Bb8KpfOKAPSSlhU0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708093226; c=relaxed/simple; bh=C+nR2DB3AL8ndZIF0jjWAs0Slpf58+Aq/pO2talJ8Lw=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=H/ZnIjbFIXb+o+TU0NdkA7sATEna+XSjFFeb7gXn4lb5xC/CzqacZf1sMWfZrfUaUPRxn5hFxhpinXwCsRbybnITElzKTGFL1VqKWD4o2dxjb4EoaNVdPjRqCTrlUEAQRdzaqIRErQNt4NicGVKSAz8jEKaIWeN5DxfPyFS9peA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-296a79e6295so1582524a91.3 for ; Fri, 16 Feb 2024 06:20:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708093223; x=1708698023; darn=sourceware.org; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=JtqOg+utdQYJmazFupUccODtqxpNDdfXpFLFfUTvYxw=; b=hLmQfqYUkENZF3a7mKixlBmOlrsYm8gTFWWcBkob634Mm4f3NmRyeFxxt/Cg6qNKjx 3AvuDuhi+NdYIFfdqrXmDqiPs2W5yD7pdaefjq6OGzFAAdka10UBjIu0YwweCliLeqQu z1/k8lHwtJcGSjugz/BrvmQcvXV6gLT6Uh9+IVAckU/ur/y3KKeu3AQ2CoeM67KQ0tIm +yozfB9f3bDWey5xc6xx11aEkkozQ8UMzkcwGHvl9Tz2FFJSZ4BYw+ls7JLkba3Jhm5H NxApKIi8h1J0+6i6eEbu5UTWL29H1PkScqLo32Z9d6yKGm2NvjZ1i7XOPXC34l4Fgo2E 0AUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708093223; x=1708698023; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=JtqOg+utdQYJmazFupUccODtqxpNDdfXpFLFfUTvYxw=; b=WHsRNG8Bm0vaUJIxG/XN1oczxgXtJ2gIiWdAuyc3xDDjnWZXmR7YLZQ81wnp+SaqyY VC4TrTVatQWJsMkx+Ge/9giYI1pGHfBZa/9vJHoHix9A+HWbtvSTYpQ5623MrJmKLLAS coVCv5qwV/QGBwGyec1VF4ihPeHODSLD0r9911SEJLcBeAQb4g7KCx8kc2JDnAIua1Bx gn7JbUxQMAi7bBDOBVEPEWzIWj3Yq9VN5O3w03cWVh6SCiCdxSKZPwqV2xjj0m6QsJ10 ioPRWoE7z93TTTxFOgfipxKjhYNE6U180Ve57letQ64N/1U8MF/lp0CcgyUttHkF5vz1 sH5A== X-Forwarded-Encrypted: i=1; AJvYcCXG4FeK5SqMnvgPRah86y7Nzlp33DRBYJ37Ku6PfP2rOiaA74OOm7smFI4nAk6hpLAb8dMHDTtlWj3FGqJGX+M3FYLD5U0WL5t3 X-Gm-Message-State: AOJu0YxN1UUaGmg/4MVxVkCXxxpF8TooJlZCWhZcCYISdVIQpHIuvCZM /hOBXmHCk2N/tTwoT6miqbncKpFX48xplxKmCDCGTmV1VOqOSpXFGiwDiC3bOUM= X-Google-Smtp-Source: AGHT+IGxEREh25eoPtn9ijbZVg7dVR16Scmq+ud3haaAtyvZ/w8OOPNq308wlqziRlmQFNV1sbTSJg== X-Received: by 2002:a17:90b:b08:b0:297:cb0:c2e0 with SMTP id bf8-20020a17090b0b0800b002970cb0c2e0mr4567732pjb.43.1708093222689; Fri, 16 Feb 2024 06:20:22 -0800 (PST) Received: from ?IPV6:2804:1b3:a7c0:8177:542a:9f26:15a9:5ce4? ([2804:1b3:a7c0:8177:542a:9f26:15a9:5ce4]) by smtp.gmail.com with ESMTPSA id sj6-20020a17090b2d8600b002967bc2c852sm22903pjb.43.2024.02.16.06.20.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 16 Feb 2024 06:20:22 -0800 (PST) Message-ID: <643c4bee-c96b-44db-9e14-761f014fab33@linaro.org> Date: Fri, 16 Feb 2024 11:20:20 -0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 10/11] stdio-common: Support large offsets with %lln Content-Language: en-US To: Florian Weimer , libc-alpha@sourceware.org References: From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 09/02/24 12:25, Florian Weimer wrote: > Use of Xprintf_buffer_done is unnecessary because it performs > overflow detection against int and sets errno. > --- > stdio-common/Makefile | 1 + > stdio-common/tst-printf-large-n.c | 81 +++++++++++++++++++++++++++++ > stdio-common/vfprintf-process-arg.c | 2 +- > 3 files changed, 83 insertions(+), 1 deletion(-) > create mode 100644 stdio-common/tst-printf-large-n.c > > diff --git a/stdio-common/Makefile b/stdio-common/Makefile > index d610ed67e6..482d841f96 100644 > --- a/stdio-common/Makefile > +++ b/stdio-common/Makefile > @@ -234,6 +234,7 @@ tests := \ > tst-printf-fp-free \ > tst-printf-fp-leak \ > tst-printf-intn \ > + tst-printf-large-n \ > tst-printf-oct \ > tst-printf-round \ > tst-printfsz \ > diff --git a/stdio-common/tst-printf-large-n.c b/stdio-common/tst-printf-large-n.c > new file mode 100644 > index 0000000000..4504a693d2 > --- /dev/null > +++ b/stdio-common/tst-printf-large-n.c > @@ -0,0 +1,81 @@ > +/* Test that %n can report values larger than INT_MAX. > + Copyright (C) 2024 Free Software Foundation, Inc. > + This file is part of the GNU C Library. > + > + The GNU C Library is free software; you can redistribute it and/or > + modify it under the terms of the GNU Lesser General Public > + License as published by the Free Software Foundation; either > + version 2.1 of the License, or (at your option) any later version. > + > + The GNU C Library is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + Lesser General Public License for more details. > + > + You should have received a copy of the GNU Lesser General Public > + License along with the GNU C Library; if not, see > + . */ > + > +#include > +#include > +#include > +#include > + > +#include > +#include > +#include > + > +static int > +do_test (void) > +{ > + enum { string_length = 1 << 28 }; > + > + FILE *fp = xfopen ("/dev/null", "w"); > + > + /* Byte-oriented streams. */ > + { > + struct support_blob_repeat repeat > + = support_blob_repeat_allocate ("a", 1, string_length + 1); > + char *string = repeat.start; > + if (string == NULL) > + FAIL_UNSUPPORTED ("cannot allocate large string"); > + string[string_length] = '\0'; > + > + long long int n; Indentation seems off here. > + TEST_COMPARE (fprintf (fp, "%s %s %s %s %s %s %s %s %lln", > + string, string, string, string, string, string, > + string, string, &n), -1); > + TEST_COMPARE (errno, EOVERFLOW); > + TEST_COMPARE (n, 8 * (string_length + 1LL)); > + TEST_VERIFY (n > INT_MAX); > + > + support_blob_repeat_free (&repeat); Here as well. > + } > + > + /* Wide-oriented streams. */ > + { > + struct support_blob_repeat repeat > + = support_blob_repeat_allocate (L"a", sizeof (wchar_t), > + string_length + 1); > + wchar_t *string = repeat.start; > + if (string == NULL) > + FAIL_UNSUPPORTED ("cannot allocate large wide string"); > + string[string_length] = '\0'; It should not matter, but maybe L'\0' here? > + > + long long int n; > + TEST_COMPARE (fwprintf (fp, L"%Ls %Ls %Ls %Ls %Ls %Ls %Ls %Ls %lln", > + string, string, string, string, string, string, > + string, string, &n), -1); > + TEST_COMPARE (errno, EOVERFLOW); > + TEST_COMPARE (n, 8 * (string_length + 1LL)); > + TEST_VERIFY (n > INT_MAX); > + > + support_blob_repeat_free (&repeat); > + } > + > + xfclose (fp); > + > + return 0; > +} > + > +#include > diff --git a/stdio-common/vfprintf-process-arg.c b/stdio-common/vfprintf-process-arg.c > index af6b570ea9..dbc78d4942 100644 > --- a/stdio-common/vfprintf-process-arg.c > +++ b/stdio-common/vfprintf-process-arg.c > @@ -337,7 +337,7 @@ LABEL (form_number): > } > /* Answer the count of characters written. */ > void *ptrptr = process_arg_pointer (); > - unsigned int written = Xprintf_buffer_done (buf); > + uint64_t written = buf->written + (buf->write_ptr - buf->write_base); > if (is_longlong) > *(long long int *) ptrptr = written; > else if (is_long_num) This is strictly an alias violation, but the rest of the code follow this pattern so it should be ok.