From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 4bHHMna5MWlMQRkAWB0awg (envelope-from ) for ; Thu, 04 Dec 2025 11:40:22 -0500 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=N7g/RGxc; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id CC2AA1E0B3; Thu, 04 Dec 2025 11:40:22 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=no autolearn_force=no version=4.0.1 Received: from sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 7430F1E08D for ; Thu, 04 Dec 2025 11:40:22 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 070C34BCA426 for ; Thu, 4 Dec 2025 16:40:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 070C34BCA426 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=N7g/RGxc Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 77E744C31818 for ; Thu, 4 Dec 2025 16:38:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 77E744C31818 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 77E744C31818 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1764866310; cv=none; b=J1OaeZ4i5D02p4J50kcogopkt/AhMD2xIV/FaSWIO00pZoUOehemXAheb7LCh/USv51FfyJTL+RxdZHU3XBF3MOSPlTigqiK1DgBYu89CQs/WTbav1YXlWeJKBJcPes2ew/ZqkeRiGav4evI6ZpqDdFd5O4j/UH5TlaW5fsEXv0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1764866310; c=relaxed/simple; bh=SMxntwgNNsqFUICqFIflLb9lJQ+q1u+ypNgq3m8Msp4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=pc8nVGf5rb9q8BIc1wSnOSZcc6PZC9AHIOaupulokACMTf6L75owEIgnSE7xHOflWd8Vx+WgTyWuQE+cb2sznP3LjmoJgRMg9L9UqHRgfWqd7JaaeucFlcTa39LXHTbB8Mi+luwR4GirQ9qfgLdLbKhg4pJiGviH6AFhLrsjYHA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 77E744C31818 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1764866310; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BHOeN+x2EKpvzmOAddkQqjgz6Z6LNXCfn8IdOZV9Rpg=; b=N7g/RGxcIxho+fO5qWvLUAxzbl06EeE+hSSFUT6bcK42JxCDPiV57T+Gm3+/CnESxJj2xG Zhj8skBO+d6C0qHWWa7flW9AxLixZqdum1dL3QalCHqu7OZNuQ8/sfLXSEuKKd7W97XZkd gWU1k/t2sX/vRixJydXnJnfBmpMn9c0= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-312-7pElcFCZPJizD7pmUOeoCQ-1; Thu, 04 Dec 2025 11:38:29 -0500 X-MC-Unique: 7pElcFCZPJizD7pmUOeoCQ-1 X-Mimecast-MFC-AGG-ID: 7pElcFCZPJizD7pmUOeoCQ_1764866307 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4775d8428e8so7666555e9.0 for ; Thu, 04 Dec 2025 08:38:27 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764866306; x=1765471106; 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=BHOeN+x2EKpvzmOAddkQqjgz6Z6LNXCfn8IdOZV9Rpg=; b=B9zKDSDf8WNJooXSIaSlfdppmDy1hF3KHQ/iGgR3llKR+cUXZAJZe7Q9tIPcQAX4CO jF6HRFqGStsSLZ7c6dzO7TIujKG3xfwT6Liy2J7GZTjauaXt4Ekyx1e96gPfW9FDgVgG PCQTEGu4P2imXwkCgDtI3w7wyAV4MH+a8m2N2YRD8DF2WZg/xsOv0CYyd/7lTlNIXqXr JTnb+H/p5ENYo6ertZ8EEXDRzaJNYi9YJPjiNP9AU5gEnPhFdpK4s7Ldg+b2woMYO48z 0jmFFeoIC9Cc7E/Umtf05b5B/1RvfxQx7oU0abrGQ8QHqpjvwYNQmfOyobSscdcPvaUh 36SQ== X-Gm-Message-State: AOJu0YzrLSWq5KMulZRXWgnA9f6UaBop9bGub75lUmm0ACWHow1KmmWW mR4aKvw5pfQsOaJdIhcSfqqS1Y/Q5XdS78lyrzbmCsIDvUPios4xsZ97COoQUboT2K5P7CG+8j+ +ZyxX5wVu6+t/XsxUUiFi6WPUzWhzC1AlzQRD2qP/P/gDYJTa78m7NTd53qaF51KMScJjJLSo7a 7Bwuxseej7ViZwGPuXHSCNj3swUefTJMl7zmY5aYu3Ye5aifE= X-Gm-Gg: ASbGnct4zSShMN7tfS/xUBPlSL8Tws1kOmAsyp+v8EqzP72aJVPzisuXAa+1moOzaPZ qxy1PRt8OAxUJ5rWzNcl1tpaFmlFWPtiiFwHu4GnYrXEojcF3TYGanuKcPXW2fvjlIV6V0ieV06 maKXegpdBNPzDc75AjQx3E2ljm/hlVYWumeeP6pTiY5Ud8XxOyFyrcmrb7aGeae4FZ2hBdwl0+O BdVOziv/9xeIpZZjM27GVy0i0K3yyhVy7JWNxFVBWOtoJVWxv+So6Q0iuIkll+fEZrjcgOyaeoO SeCW1g6yX7BNXA/2/3YIWJ+rZi9f3J14XMnMFmBByt5VnVYq/Ra3pY+UpDgwf9YD9RPxMIYbOsh MjOva X-Received: by 2002:a05:6000:24c1:b0:42b:41d3:daf1 with SMTP id ffacd0b85a97d-42f731a5cc7mr7788919f8f.38.1764866306094; Thu, 04 Dec 2025 08:38:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IELGKHAeoThE6Qth3m6eabO08jdVpGrVr3Fs/phWxgIRuTzZR2by8qqA24F6DrafkXp3wT/Pw== X-Received: by 2002:a05:6000:24c1:b0:42b:41d3:daf1 with SMTP id ffacd0b85a97d-42f731a5cc7mr7788884f8f.38.1764866305588; Thu, 04 Dec 2025 08:38:25 -0800 (PST) Received: from localhost ([31.111.84.207]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42f7d331092sm4071891f8f.30.2025.12.04.08.38.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Dec 2025 08:38:25 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Guinevere Larsen , Andrew Burgess Subject: [PATCH 3/4] gdb: make get_chars_per_line return an unsigned value Date: Thu, 4 Dec 2025 16:38:16 +0000 Message-ID: <10eed1eec274c1f0e7b5e33a8736d43813a6ba08.1764866150.git.aburgess@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: XARUFdPWLMFR3uGl6Fe2_EkGhvHhXMHJFQ2zGgRChU0_1764866307 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org I noticed that get_chars_per_line currently returns an 'int', but the value it is returning, from utils.c, is an 'unsigned int'. In some cases this can cause weird behaviour as an unlimited width terminal will have UINT_MAX characters per line, which will appear as negative when returned from get_chars_per_line. This has been the case since get_chars_per_line was added in commit: commit 2f2287318b33ddf855a692fcc191f6b25caf4644 Date: Wed Dec 16 18:18:40 2020 +0100 [gdb/cli] Add a progress meter Lets make get_chars_per_line return an unsigned value, and update all the uses of this function to hold the result in an unsigned variable. I ran into this issue when looking at print_gdb_hints (from top.c) where a very large get_chars_per_line() value would appear negative, and so the startup hints would be printed without a box when really they should have been boxed. There's no tests with this commit yet as print_gdb_hints has other bugs which will be fixed in the next commit. At this point I'll add some tests. --- gdb/cli-out.c | 4 ++-- gdb/top.c | 2 +- gdb/utils.c | 3 ++- gdb/utils.h | 5 +++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/gdb/cli-out.c b/gdb/cli-out.c index 27a82f607eb..1e52734802c 100644 --- a/gdb/cli-out.c +++ b/gdb/cli-out.c @@ -298,7 +298,7 @@ cli_ui_out::do_progress_notify (const std::string &msg, const char *unit, double howmuch, double total) { - int chars_per_line = get_chars_per_line (); + unsigned int chars_per_line = get_chars_per_line (); struct ui_file *stream = get_unbuffered (m_streams.back ()); cli_progress_info &info (m_progress_info.back ()); @@ -385,7 +385,7 @@ void cli_ui_out::clear_progress_notify () { struct ui_file *stream = get_unbuffered (m_streams.back ()); - int chars_per_line = get_chars_per_line (); + unsigned int chars_per_line = get_chars_per_line (); scoped_restore save_pagination = make_scoped_restore (&pagination_enabled, false); diff --git a/gdb/top.c b/gdb/top.c index a8ce1a5321d..1aefe74b394 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -1414,7 +1414,7 @@ box_one_message (ui_file *stream, std::string message, int width) void print_gdb_hints (struct ui_file *stream) { - int width = get_chars_per_line (); + unsigned int width = get_chars_per_line (); /* Arbitrarily setting maximum width to 80 characters, so that things are big and visible but not overwhelming. */ diff --git a/gdb/utils.c b/gdb/utils.c index ffe0d639e3a..d322843925b 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -1548,9 +1548,10 @@ gdb_flush (struct ui_file *stream) /* See utils.h. */ -int +unsigned int get_chars_per_line () { + gdb_assert (chars_per_line > 0); return chars_per_line; } diff --git a/gdb/utils.h b/gdb/utils.h index 0e28f9424e5..6316547653e 100644 --- a/gdb/utils.h +++ b/gdb/utils.h @@ -157,9 +157,10 @@ extern void wrap_here (int); extern void reinitialize_more_filter (void); -/* Return the number of characters in a line. */ +/* Return the number of characters in a line. Will never be zero, but can + be UINT_MAX, which indicates unlimited characters per line. */ -extern int get_chars_per_line (); +extern unsigned int get_chars_per_line (); extern bool pagination_enabled; -- 2.47.1