Skip to content

Commit f5ef6b8

Browse files
authored
Mark internal_error and friends as __noreturn__ (#7071)
* Mark internal_error and friends as __noreturn__ This prevents a false-positive warning seen with GCC -fsanitize=... where an allocation checked using internal_error() is considered to be possibly of size zero. Fixes: #7070 * NEWS item * NEWS entry, actually link to the issue
1 parent 5483d48 commit f5ef6b8

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242

4343
11. Out of sample type bumps now respect `integer64=` selection, [#7032](https://github.com/Rdatatable/data.table/pull/7032).
4444

45+
12. Internal functions used to signal errors are now marked as non-returning, silencing a compiler warning about potentially unchecked allocation failure. Thanks to Prof. Brian D. Ripley for the report and @aitap for the fix, [#7070](https://github.com/Rdatatable/data.table/pull/7070).
46+
4547
### NOTES
4648

4749
1. Continued work to remove non-API C functions, [#6180](https://github.com/Rdatatable/data.table/issues/6180). Thanks Ivan Krylov for the PRs and for writing a clear and concise guide about the R API: https://aitap.codeberg.page/R-api/.

src/data.table.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@
7878
#define NEED2UTF8(s) !(IS_ASCII(s) || (s)==NA_STRING || IS_UTF8(s))
7979
#define ENC2UTF8(s) (!NEED2UTF8(s) ? (s) : mkCharCE(translateCharUTF8(s), CE_UTF8))
8080

81+
// R has been providing a widely portable definition, but since that's not documented, define our own too
82+
#ifndef NORET
83+
# if defined(__GNUC__) && __GNUC__ >= 3
84+
# define NORET __attribute__((__noreturn__))
85+
# else
86+
# define NORET
87+
# endif
88+
#endif
89+
8190
// init.c
8291
extern SEXP char_integer64;
8392
extern SEXP char_ITime;
@@ -147,7 +156,7 @@ uint64_t dtwiddle(double x);
147156
SEXP forder(SEXP DT, SEXP by, SEXP retGrpArg, SEXP retStatsArg, SEXP sortGroupsArg, SEXP ascArg, SEXP naArg);
148157
SEXP forderReuseSorting(SEXP DT, SEXP by, SEXP retGrpArg, SEXP retStatsArg, SEXP sortGroupsArg, SEXP ascArg, SEXP naArg, SEXP reuseSortingArg); // reuseSorting wrapper to forder
149158
int getNumericRounding_C(void);
150-
void internal_error_with_cleanup(const char *call_name, const char *format, ...);
159+
NORET void internal_error_with_cleanup(const char *call_name, const char *format, ...);
151160

152161
// reorder.c
153162
SEXP reorder(SEXP x, SEXP order);
@@ -263,7 +272,7 @@ SEXP islockedR(SEXP x);
263272
bool need2utf8(SEXP x);
264273
SEXP coerceUtf8IfNeeded(SEXP x);
265274
SEXP coerceAs(SEXP x, SEXP as, SEXP copyArg);
266-
void internal_error(const char *call_name, const char *format, ...);
275+
NORET void internal_error(const char *call_name, const char *format, ...);
267276

268277
// types.c
269278
char *end(char *start);

0 commit comments

Comments
 (0)