Bug 13268

Summary: modf, modff, modfl: help GCC with argument checking
Product: glibc Reporter: Bruno Haible <bruno>
Component: mathAssignee: Andreas Jaeger <aj>
Status: RESOLVED FIXED    
Severity: normal CC: drepper.fsp
Priority: P2 Flags: fweimer: security-
Version: 2.11   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed:

Description Bruno Haible 2011-10-05 23:43:45 UTC
The second argument of the functions modf, modff, modfl must not be a NULL
pointer, according to POSIX, and the glibc implementation also does not allow
a NULL pointer.

It would be useful to allow GCC to give a warning when someone passes a NULL
literal to these functions.

How to reproduce:
==================== foo.c ========================
#include <math.h>
#include <stddef.h>
int
main ()
{
  return ! modf (2.4, NULL);
}
===================================================
$ gcc -Wall foo.c

Expected result:
foo.c: In function 'main':
foo.c:6:3: warning: null argument where non-null required (argument 2)

Actual result:
No diagnostic.

The fix should be easy: Add a properly conditionalized
__attribute__ ((__nonnull__ (2)))
to glibc/math/bits/mathcalls.h line 116.
Comment 1 Andreas Jaeger 2011-10-12 12:36:01 UTC
Thanks. I send a patch to libc-alpha for this.
Comment 2 Ulrich Drepper 2011-10-15 14:09:07 UTC
Changed in git.