From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by sourceware.org (Postfix) with ESMTPS id BD03238582BA for ; Fri, 16 Feb 2024 14:13:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BD03238582BA 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 BD03238582BA Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708092815; cv=none; b=ho746QFoC799URGmr2y3N/MJ1EpGWSrgWax7JNaVlKn6fPmgYvyCM4muWpAlPwbJWEoyGCE5unyDw03k3tTY8bQs3MpxfqeoXSmpUv8RWJoTZ9S8nk2VQj5Grf7+noyN7huUP97VwxVPvR+KePjXSE4YDLkCMuDkX/7oCibZJo8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708092815; c=relaxed/simple; bh=qMDIww6h89PRIs3mrKmSCsihQ1xx05TywxqfzvkPlPo=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=UAD05VRVAFsKORmMQG2XYxs4aoSNBZqodGJnxA1/T7dr93yU0SM60KVtgnF8HwaFPLnsGpXUplNcGZJLqZxAa7Hd7PPtcjMPqkeJ+2cNrTeI8FVeLWJdKNlp6Y00xepwlNzrD/HDigAN0csyB4RXBsbjqB894K419E52VyNY0u8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1d94b222a3aso20040375ad.2 for ; Fri, 16 Feb 2024 06:13:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708092812; x=1708697612; 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=lfDFmecfA2QfSYoee0sYd9iXhktylFrPUYthANi6EAY=; b=RiCQ+xfTHOvOq1e0KwBD+AHMrxp5XxPxn+iqyKZosadiaPdwQJiU9MVfA3lL19SV08 /bZVfKWLMPzTozg2ywwC8sKVrSqlEcLwfp+yOKVlX5tkHlvMZkgmZDu9TAXSD6FZ9t4I J08iw0JyUFi6bep7oRXxymrTtYqM+6qNochlEObrhognb/DGmz82UYi+bYFa4rDIFpqN /mONLKbz1sJjwr8Kd5nh9KHwsxU+tsz7DjW8P9JgC2TM00VmMcfLZoI5/bTIBc/quC9+ 2VGg4OJfMUz5jfdX+M2q6lQe/YxtFmE3aU2Tz5I2PCMiC7+tikVTeruwQGmRyTy7V4cm /h/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708092812; x=1708697612; 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=lfDFmecfA2QfSYoee0sYd9iXhktylFrPUYthANi6EAY=; b=edhVZytCiinGiQNIIYme6ThWsemv58PpEIwKaGvN7lX2YF+gNVhCji0A9swY6r+SPJ 22nMRysxXnzIQnc9wePMdUcmMqQAC2M9V83yxovZN7QJHM58bsiK7L6CIflLO9jxsTJp pBGZ/OBjETLozsYMJmQ2qTA6Bf8BA//yU2hLMibEb8cEdr5Tj4vstHlIAYULgkT+Jdze j0kBawm9WlaKrvYMHzrgXo9hFXZtij1E+CnWkQM7zGI+g5XVW89APbZsD6DaEo+GqPqw qr4S2UULcoAqieKZcrQ3s3n6ytXNrWt7X0uKcOBZfs+bKf+QbdagT34NQFBq5gdS5g9l K3vA== X-Forwarded-Encrypted: i=1; AJvYcCUrElIvV/OqKdrK/4En7OHvKOcosgkan4X6S/GboeDBQ73fesgziXZzsiGLdN+33CDy9dngAwdQpkhTwS1rlEjAmOwwu+Jw3dcy X-Gm-Message-State: AOJu0YxXGePss4ZsK+ZOorDB+UPXcLxDkPvfGSHrd1ZDcW9JBy63ei5U bsFEK0CORQzPSGlEGw4eX58cVrn1C9+vLQ26B3Po/nRA4qs7iqMsQWYZWAw3xjQ= X-Google-Smtp-Source: AGHT+IFWyz485JOrDtETfV9MJ6Jx7YiflDHTkygmXoYytcM3AlOMg46epPeTdHqNE4cSnCsm9d+LiA== X-Received: by 2002:a17:903:11c3:b0:1d7:5943:21b8 with SMTP id q3-20020a17090311c300b001d7594321b8mr6648853plh.16.1708092812318; Fri, 16 Feb 2024 06:13:32 -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 w17-20020a1709027b9100b001da15580ca8sm3039585pll.52.2024.02.16.06.13.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 16 Feb 2024 06:13:31 -0800 (PST) Message-ID: <3d0c90cc-ab86-4e14-a344-86c75feb6269@linaro.org> Date: Fri, 16 Feb 2024 11:13:30 -0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 09/11] stdio-common: Allow skipping initial bytes in __printf_buffer for %n 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.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,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: > Making the written field signed allows subtraction of a prefix count > in case multiple writes happen to the same buffer. LGTM, thanks. Reviewed-by: Adhemerval Zanella > --- > include/printf_buffer.h | 8 +++++--- > stdio-common/tst-printf_buffer.c | 18 ++++++++++++++++++ > 2 files changed, 23 insertions(+), 3 deletions(-) > > diff --git a/include/printf_buffer.h b/include/printf_buffer.h > index a5483e8a97..2400371b94 100644 > --- a/include/printf_buffer.h > +++ b/include/printf_buffer.h > @@ -92,8 +92,10 @@ struct __printf_buffer > buffer). Potentially updated on flush. The actual number of > written bytes also includes the unflushed-but-written buffer > part, write_ptr - write_base. A 64-bit value is used to avoid > - the need for overflow checks. */ > - uint64_t written; > + the need for intermediate overflow checks. Negative values can > + be used to ignore leading parts of the buffer for %n computations > + (for repeated __printf_buffer calls to the same buffer). */ > + int64_t written; > > /* Identifies the flush callback. */ > enum __printf_buffer_mode mode; > @@ -225,7 +227,7 @@ struct __wprintf_buffer > wchar_t *write_base; > wchar_t *write_ptr; > wchar_t *write_end; > - uint64_t written; > + int64_t written; > enum __wprintf_buffer_mode mode; > }; > > diff --git a/stdio-common/tst-printf_buffer.c b/stdio-common/tst-printf_buffer.c > index d12da8c939..2a3ee511d0 100644 > --- a/stdio-common/tst-printf_buffer.c > +++ b/stdio-common/tst-printf_buffer.c > @@ -132,6 +132,24 @@ do_test (void) > TEST_VERIFY (!__printf_buffer_has_failed (&buf.base)); > TEST_COMPARE (__printf_buffer_asprintf_free (&buf), -1); > } > + > + /* Test %n with initial skip. */ > + { > + struct __printf_buffer_asprintf buf; > + __printf_buffer_asprintf_init (&buf); > + __printf_buffer (&buf.base, "abc"); > + buf.base.written = -2; > + int n = -1; > + __printf_buffer (&buf.base, "D%nEF", &n); > + TEST_COMPARE (n, 2); /* Two characters were skipped. */ > + TEST_VERIFY (buf.base.write_base == buf.direct); > + TEST_COMPARE_BLOB (buf.base.write_base, > + buf.base.write_ptr - buf.base.write_base, "abcDEF", 6); > + TEST_VERIFY (!__printf_buffer_has_failed (&buf.base)); > + TEST_COMPARE (__printf_buffer_done (&buf.base), 4); /* Two skipped. */ > + TEST_COMPARE (__printf_buffer_asprintf_free (&buf), -1); > + } > + > return 0; > } >