From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 99761 invoked by alias); 2 Sep 2015 08:11:28 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 99696 invoked by uid 48); 2 Sep 2015 08:11:24 -0000 From: "xuejuncao at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/67433] ?: expression returns unexpected value when condition is a bool variable which memory is not true/false Date: Wed, 02 Sep 2015 08:11:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 6.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: xuejuncao at gmail dot com X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: INVALID X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-09/txt/msg00121.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67433 --- Comment #3 from xuejuncao --- (In reply to Andrew Pinski from comment #2) > Bool can only be 0 or 1, any other value causes undefined behavior. but it seems like a trap, the below code will not work fine, and will make program abort. (expect to write "1/0" that only takes 1 byte, but write 2 bytes when value is negative) https://github.com/google/protobuf/blob/master/src/google/protobuf/wire_format_lite_inl.h inline void WireFormatLite::WriteBoolNoTag(bool value, io::CodedOutputStream* output) { output->WriteVarint32(value ? 1 : 0); }