From 73a39a3f7a9ef3004fb131732d8cc787dd79403d Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Tue, 27 Jun 2023 17:19:19 -0400 Subject: [PATCH 85/98] FIXME: add test: atoi.c --- gcc/testsuite/c-c++-common/analyzer/atoi.c | 56 ++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 gcc/testsuite/c-c++-common/analyzer/atoi.c diff --git a/gcc/testsuite/c-c++-common/analyzer/atoi.c b/gcc/testsuite/c-c++-common/analyzer/atoi.c new file mode 100644 index 000000000000..f73f9579f558 --- /dev/null +++ b/gcc/testsuite/c-c++-common/analyzer/atoi.c @@ -0,0 +1,56 @@ +/* See e.g. https://en.cppreference.com/w/c/string/byte/atoi + and https://www.man7.org/linux/man-pages/man3/atoi.3.html */ + +extern int atoi (const char *str); + +int +test_passthrough (const char *str) +{ + return atoi (str); +} + +void +test_known (void) +{ + __analyzer_eval (atoi ("0") == 0); /* { dg-warning "UNKNOWN" } */ + __analyzer_eval (atoi (" 3.14159") == 3); /* { dg-warning "UNKNOWN" } */ + __analyzer_eval (atoi (" -17junk") == -17); /* { dg-warning "UNKNOWN" } */ + __analyzer_eval (atoi ("blah") == 0); /* { dg-warning "UNKNOWN" } */ +} + +double +test_null (void) +{ + return atoi (NULL); // FIXME: complain about this? +} + +double +test_uninit (void) +{ + const char buf[10]; + return atoi (buf); // FIXME: complain about this? +} + +double +test_not_terminated (void) +{ + const char buf[3] = "foo"; + return atoi (buf); // FIXME: complain about this? +} + +/* TODO: + "Interprets an integer value in a byte string pointed to by str. The implied radix is always 10." + + "Discards any whitespace characters until the first non-whitespace character is found, then takes as many characters as possible to form a valid integer number representation and converts them to an integer value. The valid integer value consists of the following parts:" + + (optional) plus or minus sign + numeric digits + + "If the value of the result cannot be represented, i.e. the converted value falls out of range of the corresponding return type, the behavior is undefined." + + "Return value: Integer value corresponding to the contents of str on success." + "If no conversion can be performed, ​0​ is returned. " + + + */ + -- 2.49.0