From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12295 invoked by alias); 12 Dec 2012 04:13:22 -0000 Received: (qmail 9490 invoked by uid 22791); 12 Dec 2012 04:13:17 -0000 X-SWARE-Spam-Status: No, hits=-4.6 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,KHOP_THREADED,RCVD_IN_HOSTKARMA_W,RCVD_IN_HOSTKARMA_WL X-Spam-Check-By: sourceware.org Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 12 Dec 2012 04:13:10 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1Tidgx-0001Db-Id from Yao_Qi@mentor.com for gdb-patches@sourceware.org; Tue, 11 Dec 2012 20:13:07 -0800 Received: from SVR-ORW-FEM-05.mgc.mentorg.com ([147.34.97.43]) by SVR-ORW-EXC-10.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Tue, 11 Dec 2012 20:13:07 -0800 Received: from qiyao.dyndns.org.dyndns.org (147.34.91.1) by svr-orw-fem-05.mgc.mentorg.com (147.34.97.43) with Microsoft SMTP Server id 14.1.289.1; Tue, 11 Dec 2012 20:13:06 -0800 From: Yao Qi To: Subject: [PATCH 3/3] Assert 'printf_line' is non-null. Date: Wed, 12 Dec 2012 04:13:00 -0000 Message-ID: <1355285581-28889-4-git-send-email-yao@codesourcery.com> In-Reply-To: <1355285581-28889-1-git-send-email-yao@codesourcery.com> References: <1355285581-28889-1-git-send-email-yao@codesourcery.com> MIME-Version: 1.0 Content-Type: text/plain X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2012-12/txt/msg00375.txt.bz2 As we can see the code above, printf_line is always assigned to a non-null string, so this patch removes the check on 'printf_line' and add an assert. On the other hand, 'breakpoint_set_commands' will be called unconditionally, and B->commands is non-null (B is a dprintf). gdb: 2012-12-12 Yao Qi * breakpoint.c (update_dprintf_command_list): Assert that 'printf_line' is non-null. Remove condition check. --- gdb/breakpoint.c | 40 ++++++++++++++++++++-------------------- 1 files changed, 20 insertions(+), 20 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 65bdc2c..ab056d4 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -8865,30 +8865,30 @@ update_dprintf_command_list (struct breakpoint *b) internal_error (__FILE__, __LINE__, _("Invalid dprintf style.")); + gdb_assert (printf_line != NULL); /* Manufacture a printf/continue sequence. */ - if (printf_line) - { - struct command_line *printf_cmd_line, *cont_cmd_line = NULL; + { + struct command_line *printf_cmd_line, *cont_cmd_line = NULL; - if (strcmp (dprintf_style, dprintf_style_agent) != 0) - { - cont_cmd_line = xmalloc (sizeof (struct command_line)); - cont_cmd_line->control_type = simple_control; - cont_cmd_line->body_count = 0; - cont_cmd_line->body_list = NULL; - cont_cmd_line->next = NULL; - cont_cmd_line->line = xstrdup ("continue"); - } + if (strcmp (dprintf_style, dprintf_style_agent) != 0) + { + cont_cmd_line = xmalloc (sizeof (struct command_line)); + cont_cmd_line->control_type = simple_control; + cont_cmd_line->body_count = 0; + cont_cmd_line->body_list = NULL; + cont_cmd_line->next = NULL; + cont_cmd_line->line = xstrdup ("continue"); + } - printf_cmd_line = xmalloc (sizeof (struct command_line)); - printf_cmd_line->control_type = simple_control; - printf_cmd_line->body_count = 0; - printf_cmd_line->body_list = NULL; - printf_cmd_line->next = cont_cmd_line; - printf_cmd_line->line = printf_line; + printf_cmd_line = xmalloc (sizeof (struct command_line)); + printf_cmd_line->control_type = simple_control; + printf_cmd_line->body_count = 0; + printf_cmd_line->body_list = NULL; + printf_cmd_line->next = cont_cmd_line; + printf_cmd_line->line = printf_line; - breakpoint_set_commands (b, printf_cmd_line); - } + breakpoint_set_commands (b, printf_cmd_line); + } } /* Update all dprintf commands, making their command lists reflect -- 1.7.7.6