From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 956633858D20 for ; Mon, 6 Nov 2023 16:56:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 956633858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none 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 956633858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699289789; cv=none; b=vXWHKv+p2p5yifNZHopvcYAkE7hQRCOqO46P5KOjJ4/R64/8/JUu8O2/AO3B0MxY0HljT+qKgK5/3CrUTyHN9MXVd765S9LXaoSpRJ3LMHlKro1ddS6PkN4owWCCFB9E0aQmxT+lVQXVa+/cBdCTO97BL+WfgFNv5aUAWSGHO4A= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699289789; c=relaxed/simple; bh=9lXQ0riQMiHXg8SgkaoZoililboVzt7kPMweRNdzvjk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=SJDru+d6qEjvap10x0zoQ+DkPfub/aoXS9nwhfpFv9xMDfDjgzetsd8g5LHku42EOvb4NE3Lbu8LYevaHNRMHODnQPpvLMasNQvBAZTusoJTbSMoMpZkscJ2UFdaUfnj7WgV5eEMRXZ3HOz5g6wYcwqoU5J+RCNFaH4aCY3BIgo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699289785; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=72rcveVmVXTpWAQGoOwXqN/eg66RKLUD6P6+Q0uLFcY=; b=PwfhDlBLg0RS8sTkESm9yUm5e2ISQba+g6kZl3iACiyOlCBRV6MjDpqMbpzhERBvHY49Sk tReKbIyIVZZHesOp1Fywy5sNl3L7bmbovDqhBLg827db1MIO7whvytNHg3jyBhviS9j+y5 /ss8dDRvEqAi7g+T5eCwj1d3L7ryqp8= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-609-NF8ZvPRaNb6dEil0BYQeaQ-1; Mon, 06 Nov 2023 11:56:06 -0500 X-MC-Unique: NF8ZvPRaNb6dEil0BYQeaQ-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-41e16b279ffso52085561cf.0 for ; Mon, 06 Nov 2023 08:56:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699289766; x=1699894566; h=mime-version:message-id:date:references:in-reply-to:subject:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=72rcveVmVXTpWAQGoOwXqN/eg66RKLUD6P6+Q0uLFcY=; b=lR8b8OBa/a6I0W2cvcGkbMnd/3MFnlZ5JVrwHkMQMlPtUBmJpxoDLLzPH6J4sDVwNW nKMNccKqE3VB7JFd21C4LqHHgK9LekFRaUo8KqnLsgL1vRHrxKUdg8Txuo4HeR2EwU10 uDMavN/LHt7DRMI4nsFc9y5+rXnOf04Z6jFpO93tYsQoxJ8/ujGMjO8/uBaCgi4jXU0H DOi1sUYsijwzoVnDRtoimnaoChAuNf5xySgWfpoAH89k/jqRbaCDCoTBiESer+2DEaP4 pVOEv/bplCze1VFGkXuqWkGQPaUgaC71Tk53h0TOAM7f1fg7EbhABbrUO6qitZPqIU+4 UP2g== X-Gm-Message-State: AOJu0YwEXqYV8/07vwKd1HWKCpfnuWaPXNxhI55r1tczrEIwjy2rpJ6E stZya6C6k/FA7nzlQMT32DyA+a7RnkgUw6OwUQMF9/7eouhu54HZN+G6CkGqE0HbgFgQLLQtn7s wdRsMU51vG121jBDG0vFMuw== X-Received: by 2002:a05:622a:315:b0:41e:24bc:b94a with SMTP id q21-20020a05622a031500b0041e24bcb94amr34549555qtw.28.1699289766066; Mon, 06 Nov 2023 08:56:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IFb8Yq33XLmI54KBXLqgdCCa1giC22wON7DcxKJlDZFDHj8Fdjr5N0hXHSAfdtt0Q+ymrcPFw== X-Received: by 2002:a05:622a:315:b0:41e:24bc:b94a with SMTP id q21-20020a05622a031500b0041e24bcb94amr34549539qtw.28.1699289765718; Mon, 06 Nov 2023 08:56:05 -0800 (PST) Received: from localhost (105.226.159.143.dyn.plus.net. [143.159.226.105]) by smtp.gmail.com with ESMTPSA id u15-20020a05622a198f00b0041977932fc6sm3533664qtc.18.2023.11.06.08.56.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 08:56:05 -0800 (PST) From: Andrew Burgess To: Hannes Domani , gdb-patches@sourceware.org Subject: Re: [PATCH] Fix resizing of TUI python windows In-Reply-To: <20231103164001.3464-1-ssbssa@yahoo.de> References: <20231103164001.3464-1-ssbssa.ref@yahoo.de> <20231103164001.3464-1-ssbssa@yahoo.de> Date: Mon, 06 Nov 2023 16:56:03 +0000 Message-ID: <87msvqu8gs.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,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: Hannes Domani writes: > When resizing from a big to small terminal size, and you have a > TUI python window that would then be outside of the new size, > valgrind shows this error: > > ==3389== Invalid read of size 1 > ==3389== at 0xC3DFEE: wnoutrefresh (lib_refresh.c:167) > ==3389== by 0xC3E3C9: wrefresh (lib_refresh.c:63) > ==3389== by 0xA9766C: tui_unhighlight_win(tui_win_info*) (tui-wingeneral.c:134) > ==3389== by 0x98921C: tui_py_window::rerender() (py-tui.c:183) > ==3389== by 0xA8C23C: tui_layout_split::apply(int, int, int, int, bool) (tui-layout.c:1030) > ==3389== by 0xA8C2A2: tui_layout_split::apply(int, int, int, int, bool) (tui-layout.c:1033) > ==3389== by 0xA8C23C: tui_layout_split::apply(int, int, int, int, bool) (tui-layout.c:1030) > ==3389== by 0xA8B1F8: tui_apply_current_layout(bool) (tui-layout.c:81) > ==3389== by 0xA95CDB: tui_resize_all() (tui-win.c:525) > ==3389== by 0xA95D1E: tui_async_resize_screen(void*) (tui-win.c:562) > ==3389== by 0x6B855D: invoke_async_signal_handlers() (async-event.c:234) > ==3389== by 0xC0CEF8: gdb_do_one_event(int) (event-loop.cc:199) > ==3389== Address 0x115cc214 is 1,332 bytes inside a block of size 2,240 free'd > ==3389== at 0x4A0A430: free (vg_replace_malloc.c:446) > ==3389== by 0xC3CF7D: _nc_freewin (lib_newwin.c:121) > ==3389== by 0xA8B1C6: tui_apply_current_layout(bool) (tui-layout.c:78) > ==3389== by 0xA95CDB: tui_resize_all() (tui-win.c:525) > ==3389== by 0xA95D1E: tui_async_resize_screen(void*) (tui-win.c:562) > ==3389== by 0x6B855D: invoke_async_signal_handlers() (async-event.c:234) > ==3389== by 0xC0CEF8: gdb_do_one_event(int) (event-loop.cc:199) > ==3389== by 0x8E40E9: captured_command_loop() (main.c:407) > ==3389== by 0x8E5E54: gdb_main(captured_main_args*) (main.c:1324) > ==3389== by 0x62AC04: main (gdb.c:39) > > It's because tui_py_window::m_inner_window still has the outside > coordinates, and wnoutrefresh then does an out-of-bounds access. > > Fix this by resetting m_inner_window on every resize, it will anyways > be recreated in the next rerender call. Yeah, I wonder why we do it that way. It feels like calling wclear() might be more efficient. Still given where we are I think your fix makes sense. Approved-By: Andrew Burgess Thanks, Andrew > --- > gdb/python/py-tui.c | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/gdb/python/py-tui.c b/gdb/python/py-tui.c > index 64f22dbb462..a84e38a0563 100644 > --- a/gdb/python/py-tui.c > +++ b/gdb/python/py-tui.c > @@ -102,6 +102,8 @@ class tui_py_window : public tui_win_info > tui_win_info::refresh_window (); > } > > + void resize (int height, int width, int origin_x, int origin_y) override; > + > void click (int mouse_x, int mouse_y, int mouse_button) override; > > /* Erase and re-box the window. */ > @@ -232,6 +234,14 @@ tui_py_window::do_scroll_vertical (int num_to_scroll) > } > } > > +void > +tui_py_window::resize (int height_, int width_, int origin_x_, int origin_y_) > +{ > + m_inner_window.reset (nullptr); > + > + tui_win_info::resize (height_, width_, origin_x_, origin_y_); > +} > + > void > tui_py_window::click (int mouse_x, int mouse_y, int mouse_button) > { > -- > 2.35.1