From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 1qr3KTuBX2rgdSAAWB0awg (envelope-from ) for ; Tue, 21 Jul 2026 10:24:59 -0400 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=IC8uXnFZ; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 977BF1E09E; Tue, 21 Jul 2026 10:24:59 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.4 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_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.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 A2E761E099 for ; Tue, 21 Jul 2026 10:24:58 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 01AAE4BA2E08 for ; Tue, 21 Jul 2026 14:24:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 01AAE4BA2E08 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=IC8uXnFZ 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 EBEFD4BA2E08 for ; Tue, 21 Jul 2026 14:24:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EBEFD4BA2E08 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 EBEFD4BA2E08 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1784643871; cv=none; b=ckazUrYhmHA87+FvLNF082I/7eFDTyztjyS3EjiACibGPjwR0LXqcGtUVW3oO5kVs4ilBXbionvcgxBhRjVkZwCJrY0etJr1KBydzLEeyZdsQjwuKXoUuEJMPVBTGw/fGElCgnlXaTS0D1eZn/TaXP7MTTbQ+FeibSqSPV2yTQU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1784643871; c=relaxed/simple; bh=x0Y/Pr2zYJuGeGnUX/Yt6x47scY5QlGWuUgVdDpdyRM=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=NH6VRIhCl8fzagyLX+264NIcxWL1+rhuRy7hpXpJd/ME4+zKgbKIyC1N0+FYOi873MXhm2ksS8ShJ8bXRZYzuNli5BAc6BziYx9IH+e6ghzZTKy0VJngEdLMydCEGI1pK2YaNII8Pcvl0osHS3QriQ3SkgD33fQ+kglsiJHeayY= ARC-Authentication-Results: i=1; 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=IC8uXnFZ DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EBEFD4BA2E08 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1784643870; 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; bh=0TcRvR2MsdO4rtBmP/KlkTEGn5vjWhJkwLx3CBIfnNM=; b=IC8uXnFZ581kSyO9PBUTh/kieOay/IUbztbBUiCj6++2bXEqiwRtF/9577vEqHwZ++3xHg sG1OVnlQJ+1LK7M6w06HtPtjdc7SJeSS7r+lI0tUZyRmxmRTxWJPNPnxopyQR4KWZjF1fb mtWcbocBCZBYpSq3/f/XZEAScUQiaco= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-138-ip3TisFcPWyJ0AB9H0h9Tw-1; Tue, 21 Jul 2026 10:24:29 -0400 X-MC-Unique: ip3TisFcPWyJ0AB9H0h9Tw-1 X-Mimecast-MFC-AGG-ID: ip3TisFcPWyJ0AB9H0h9Tw_1784643868 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-490a767b782so59454395e9.2 for ; Tue, 21 Jul 2026 07:24:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784643868; x=1785248668; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=0TcRvR2MsdO4rtBmP/KlkTEGn5vjWhJkwLx3CBIfnNM=; b=VFSQeiY4Fe8ryJzi4bluqRYyDSjfz2OWUKGwmA4sZDQ/sBYYMr/smE2K+eRcHAkAX4 K0qtHCn9o18XDh+widwcHGfT2G9glct71QieMRmSL4XlnBTnz0qEYV7k50CImb+Aua6i fGi8NnLOpGt+7t6euslGOb3ac3FwShIJgwXhg/TGaoE3izA/PyC0vFhp0OC+cWO5hFV0 YJ9eofTkc5/EmOAFrkdzGGAo1HJ1X6mcKlMRPXyenXJYueDBDajiJ1ZQ8jOxl7nqKQ1q 7kPMKiYk60k129CMjM6jrlvN55JndvDSOisyrE738iic/3T4aveSP/lP8uYxZz9cwnDk L46A== X-Gm-Message-State: AOJu0YwM+AVWkj1wreVkGX0SGIVCqIOWe7iHUTOA1LbnjTmaRGgQQqk9 8knXD45SY2uQHiTodcJd86QrDkAd2Pkh9t4iG4p7o7fJTFmSSSsUj2BCeYEllbSCimQ7Tg8QRI4 X6kN9NEu/kXgVlYbrFoW5eogcJidDRKg1HIOK2TJWtmSYfRgS92BJOGgtup+UvVDi6vRwEXnuQy K51FpCL6r2VM5ltDz4YQudI/dDTRsgfV/tK5vFiSXkOBHxpb4= X-Gm-Gg: AfdE7clsRboL2s1WWiIsrncHBHURJN/SPeNG50WRqRAFJ0wf+YwFXMH1IXQoeMWfgID w6qUs9foykgcVbpn5M0aqCShHHVnGp8DhjRDzT7jIqKYyIJGf7+iMuwP9GWd0AifLtAXLBLKDdX 1KBSLQdkVAfBQM8HWEIz3PD26EWOmyKuit88+ALLAKxedAqgj/YK3Tel9R8bwplnHW6CpY0Vdi5 cmrKfOBKUIMt/6DbtXMJ9KwzQzjoYvKkKceendiuUiSEeP5Dj3dOlXv3WTqSRswtZL9QsOjQNo0 6MSStXPVqEAWF4QXsFn83COvVJ4nj2bjrTU/wgMhGOViiancqwEjGeVfrZuyfMK9nBaDEjmY X-Received: by 2002:a05:600c:4f92:b0:493:bd2a:93be with SMTP id 5b1f17b1804b1-4954a3d0ce2mr207667615e9.6.1784643867706; Tue, 21 Jul 2026 07:24:27 -0700 (PDT) X-Received: by 2002:a05:600c:4f92:b0:493:bd2a:93be with SMTP id 5b1f17b1804b1-4954a3d0ce2mr207667295e9.6.1784643867154; Tue, 21 Jul 2026 07:24:27 -0700 (PDT) Received: from localhost ([31.111.209.233]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4955df9d2f6sm134797125e9.4.2026.07.21.07.24.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jul 2026 07:24:26 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess , jakob.schaeffeler@tum.de Subject: [PATCH] gdb/tui: use init_extended_color where possible Date: Tue, 21 Jul 2026 15:24:23 +0100 Message-Id: X-Mailer: git-send-email 2.25.4 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: xmqcIgv2pMTRueJVnZu_P8AH3EE4-6feOBar_TrK3Ac_1784643868 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 After commit: commit fbe7f20a0f098ca03913452b29f50f0dc8568f77 Date: Sat May 9 23:27:43 2026 +0200 gdb/tui: fix unexpected reuse of color pairs which converted GDB to use init_extended_pair where possible, I realised we could also make use of init_extended_color. The motivation for using init_extended_color is slightly less than init_extended_pair. Assuming the terminal supports it the standard init_color API supports up to SHRT_MAX (32767) different colors, switching to init_extended_color removes the SHRT_MAX limit on color indices, allowing us to support the full range of COLORS. But the cost of making this change is minimal, we already track the color indices as an `int` within the global COLOR_MAP, so it's mostly just a case of calling init_extended_color where needed. We only use init_extended_color when both that function and init_extended_pair is available. The fallback to init_extended_pair is init_pair, which expects the color indices to be shorts. If we are using the init_pair fallback then using init_extended_color is pointless. In reality init_extended_pair and init_extended_color were both added in ncurses 6.1, so should both be available together. There is one additional change in here. Assuming that a terminal does support more than SHRT_MAX colours, but for some reason GDB is compiled with a version of the curses library that doesn't support init_extended_color, then it is possible that in `get_color` the value of NEXT could end up above SHRT_MAX, in which case the `init_color` call will truncate the value of NEXT to a short and we will end up redefining an earlier color index. To avoid this unlikely case I've added a compare against SHRT_MAX. The init_extended_color path doesn't have this risk as COLORS is an `int` and NEXT is passed as an `int` on this path so there is no risk of truncation. --- gdb/config.in | 3 +++ gdb/configure | 1 + gdb/configure.ac | 1 + gdb/tui/tui-io.c | 20 +++++++++++++++++--- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/gdb/config.in b/gdb/config.in index 1ef5dc5c2f4..74745665d4d 100644 --- a/gdb/config.in +++ b/gdb/config.in @@ -250,6 +250,9 @@ /* Define to 1 if you have the `iconvlist' function. */ #undef HAVE_ICONVLIST +/* Define to 1 if you have the `init_extended_color' function. */ +#undef HAVE_INIT_EXTENDED_COLOR + /* Define to 1 if you have the `init_extended_pair' function. */ #undef HAVE_INIT_EXTENDED_PAIR diff --git a/gdb/configure b/gdb/configure index 303d6ea011c..fe58ba47e73 100755 --- a/gdb/configure +++ b/gdb/configure @@ -30238,6 +30238,7 @@ for ac_func in \ getrlimit \ getuid \ iconvlist \ + init_extended_color \ init_extended_pair \ libiconvlist \ posix_madvise \ diff --git a/gdb/configure.ac b/gdb/configure.ac index e55a733fba7..3d8847df9d8 100644 --- a/gdb/configure.ac +++ b/gdb/configure.ac @@ -1520,6 +1520,7 @@ AC_CHECK_FUNCS([ \ getrlimit \ getuid \ iconvlist \ + init_extended_color \ init_extended_pair \ libiconvlist \ posix_madvise \ diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c index 896d00f44c8..1c430f2ea45 100644 --- a/gdb/tui/tui-io.c +++ b/gdb/tui/tui-io.c @@ -252,10 +252,24 @@ get_color (const ui_file_style::color &color, int *result) if (next >= COLORS) return false; rgb_color rgb = color.get_rgb (); - /* We store RGB as 0..255, but curses wants 0..1000. */ - if (init_color (next, rgb[0] * 1000 / 255, rgb[1] * 1000 / 255, - rgb[2] * 1000 / 255) == ERR) + /* We store RGB as 0..255, but curses wants 0..1000. There's no + point using init_extended_color if init_extended_pair is not + available as the fallback init_pair can only handle short + color IDs. */ +#if defined HAVE_INIT_EXTENDED_COLOR && defined HAVE_INIT_EXTENDED_PAIR + if (init_extended_color (next, rgb[0] * 1000 / 255, + rgb[1] * 1000 / 255, + rgb[2] * 1000 / 255) == ERR) return false; +#else + /* NEXT is an int, but is passed as a short. If COLORS is + more than SHRT_MAX then NEXT will be truncated and end up + redefining a color entry that we don't expect. */ + if (next > SHRT_MAX + || init_color (next, rgb[0] * 1000 / 255, rgb[1] * 1000 / 255, + rgb[2] * 1000 / 255) == ERR) + return false; +#endif color_map[color] = next; *result = next; } base-commit: fbe7f20a0f098ca03913452b29f50f0dc8568f77 -- 2.25.4