| Deutsch English Français Italiano |
|
<v57cd5$3u0f8$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Thiago Adams <thiago.adams@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: Fixing a sample from K&R book using cake static analyser
Date: Sat, 22 Jun 2024 17:32:36 -0300
Organization: A noiseless patient Spider
Lines: 44
Message-ID: <v57cd5$3u0f8$1@dont-email.me>
References: <v53sl1$35qt7$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 22 Jun 2024 22:32:37 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="11bc32a71a426a96af0097ab1f695acf";
logging-data="4129256"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX199+q2W/T9ZPc4hxWuAfi34n6GmFlgi+GE="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:CLP6oZ0Y6ou8ui7U/REfdaZUiVE=
In-Reply-To: <v53sl1$35qt7$1@dont-email.me>
Content-Language: en-GB
Bytes: 2631
Link for the sample using GCC and CLANG (no warnings in both)
GCC https://godbolt.org/z/rGre3hbE1
CLANG https://godbolt.org/z/ez114sEMW
For this other sample, the compiler needs to track the state of p inside
conditional expressions. This check is wrong (p || p->text) cake and GCC
shows that.
#pragma safety enable
#include <stdlib.h>
#include <string.h>
struct X {
char * _Owner _Opt text;
};
int main() {
struct X * _Owner _Opt p = calloc(1, sizeof * p);
if (p || p->text){
p->text = strdup("a");
}
free(p->text);
free(p);
}
cake
http://thradams.com/cake/playground.html?code=CiNwcmFnbWEgc2FmZXR5IGVuYWJsZSAKCiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHN0cmluZy5oPgoKc3RydWN0IFggewogIGNoYXIgKiBfT3duZXIgX09wdCB0ZXh0Owp9OwoKaW50IG1haW4oKSB7ICAgCiAgIHN0cnVjdCBYICogX093bmVyIF9PcHQgcCA9IGNhbGxvYygxLCBzaXplb2YgKiBwKTsKICAgaWYgKHAgfHwgcC0%2BdGV4dCl7ICAgCiAgICAgcC0%2BdGV4dCA9IHN0cmR1cCgiYSIpOyAgICAgCiAgIH0KICAgZnJlZShwLT50ZXh0KTsKICAgZnJlZShwKTsgIAp9CgoKCg%3D%3D&to=-1&options=
GCC
https://godbolt.org/z/4jdc7r9r3
GCC
does NOT detects this one
https://godbolt.org/z/T6GhfzrKT
and cake does
http://thradams.com/cake/playground.html?code=CiNwcmFnbWEgc2FmZXR5IGVuYWJsZSAKCiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHN0cmluZy5oPgoKc3RydWN0IFggewogIGNoYXIgKiBfT3duZXIgX09wdCB0ZXh0Owp9OwoKaW50IG1haW4oKSB7ICAgCiAgIHN0cnVjdCBYICogX093bmVyIF9PcHQgcCA9IGNhbGxvYygxLCBzaXplb2YgKiBwKTsKICAgaWYgKHAgKXsgICAKICAgICBwLT50ZXh0ID0gc3RyZHVwKCJhIik7ICAgICAKICAgfQogICAvL2ZyZWUocC0%2BdGV4dCk7CiAgIGZyZWUocCk7ICAKfQoKCgo%3D&to=-1&options=