Bug 15028 - typdef int bool seems unsafe
Summary: typdef int bool seems unsafe
Status: RESOLVED FIXED
Alias: None
Product: Samba 4.1 and newer
Classification: Unclassified
Component: Build (show other bugs)
Version: 4.16.0
Hardware: All All
: P5 normal (vote)
Target Milestone: ---
Assignee: Samba QA Contact
QA Contact: Samba QA Contact
URL:
Keywords:
: 12474 (view as bug list)
Depends on:
Blocks:
 
Reported: 2022-03-22 03:27 UTC by Andrew Bartlett
Modified: 2022-04-04 16:30 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Bartlett 2022-03-22 03:27:55 UTC
If we use 'typedef int bool' then this expression will evaluate differently. 

int main() {
	bool foo = (4 & 4);
	if (foo == true) {
		exit(1);
	} else {
		exit(2);
	}
}

Bug filed so we can backport as this will likely catch someone out doing a backport otherwise.

_Bool which libreplace accepts, is in C99 per wikipedia, as is bool.
Comment 1 Stefan Metzmacher 2022-03-22 08:51:08 UTC
Did you actually saw problems related to this somewhere?
Comment 2 Andrew Bartlett 2022-03-22 08:55:37 UTC
No, but was writing code that came close and thought this could bite someone - probably me - later, so wanted to close it off.

https://gitlab.com/samba-team/samba/-/merge_requests/2437/diffs?commit_id=849f0321c00d1dd4b56d8bc207479e4750f7b828#5da6c41bbf6939d3d3a303b652b67bbf42b15e4f_623_653

came close, but is safe, but I felt like fixing it for an == true case.
Comment 3 Samba QA Contact 2022-03-23 12:32:04 UTC
This bug was referenced in samba master:

c0f5af21acb8018a5e53d25f1560d2a96b79a7c0
Comment 4 Stefan Metzmacher 2022-03-29 12:02:44 UTC
Fixed for 4.17
Comment 5 Björn Jacke 2022-04-04 16:30:16 UTC
*** Bug 12474 has been marked as a duplicate of this bug. ***