From c201cf3559c1e1d59a434188179f12dd203a536c Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Tue, 27 Jun 2023 17:19:12 -0400 Subject: [PATCH 84/98] FIXME: add test: atof.c --- gcc/testsuite/c-c++-common/analyzer/atof.c | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 gcc/testsuite/c-c++-common/analyzer/atof.c diff --git a/gcc/testsuite/c-c++-common/analyzer/atof.c b/gcc/testsuite/c-c++-common/analyzer/atof.c new file mode 100644 index 000000000000..aa1cfb4392db --- /dev/null +++ b/gcc/testsuite/c-c++-common/analyzer/atof.c @@ -0,0 +1,50 @@ +/* See e.g. https://en.cppreference.com/w/c/string/byte/atof + and https://www.man7.org/linux/man-pages/man3/atof.3.html */ + +#include "analyzer-decls.h" + +double atof (const char* str); +#define NULL ((void *)0) + +double +test_passthrough (const char* str) +{ + return atof (str); +} + +void +test_known (void) +{ + __analyzer_eval (atof ("0") == 0); /* { dg-warning "UNKNOWN" } */ + __analyzer_eval (atof (" 3.14159") == 3.14159); /* { dg-warning "UNKNOWN" } */ + __analyzer_eval (atof (" -17junk") == -17.); /* { dg-warning "UNKNOWN" } */ + __analyzer_eval (atof ("blah") == 0); /* { dg-warning "UNKNOWN" } */ +} + +double +test_null (void) +{ + return atof (NULL); // FIXME: complain about this? +} + +double +test_uninit (void) +{ + const char buf[10]; + return atof (buf); // FIXME: complain about this? +} + +double +test_not_terminated (void) +{ + const char buf[3] = "foo"; + return atof (buf); // FIXME: complain about this? +} + +/* TODO: test coverage. */ + +/* TODO: + similar for: + - atoi + - atol + - atoll. */ -- 2.49.0