[v2] Remove check for NULL buffer passed to `ptsname_r'

Message ID 20170529154648.GA21435@aloka.lostca.se
State New, archived
Headers

Commit Message

Arjun Shankar May 29, 2017, 3:46 p.m. UTC
  `ptsname_r' is declared in stdlib.h to only accept a `nonnull'
second argument and therefore GCC may choose to make optimizations
based on the assumption that this argument is NULL. This means
that potentially, GCC can optimize away the NULL check at some
point in the future. Since this is a programming interface, we
might as well remove the NULL check ourselves.

This also warrants a change to the `ptsname_r' manual page that
must be submitted to the corresponding mailing list.

In addition, remove the NULL buffer test in login/tst-ptsname.c.

ChangeLog:

2017-05-29  Arjun Shankar  <arjun.is@lostca.se>

	* sysdeps/unix/sysv/linux/ptsname.c (__ptsname_internal):
	Remove check for NULL 'buf'.
	* login/tst-ptsname.c (do_test): Remove test with NULL 'buf'.
---
Discussion on PATCH v1:
https://sourceware.org/ml/libc-alpha/2017-05/msg00726.html

 login/tst-ptsname.c               | 1 -
 sysdeps/unix/sysv/linux/ptsname.c | 6 ------
 2 files changed, 7 deletions(-)
  

Patch

diff --git a/login/tst-ptsname.c b/login/tst-ptsname.c
index be8744d..96f0449 100644
--- a/login/tst-ptsname.c
+++ b/login/tst-ptsname.c
@@ -70,7 +70,6 @@  do_test (void)
   if (fd != -1)
     {
       result |= do_single_test (fd, buf, sizeof (buf), 0);
-      result |= do_single_test (fd, NULL, sizeof (buf), EINVAL);
       result |= do_single_test (fd, buf, 1, ERANGE);
       close (fd);
     }
diff --git a/sysdeps/unix/sysv/linux/ptsname.c b/sysdeps/unix/sysv/linux/ptsname.c
index e3f2ae8..41bb0bb 100644
--- a/sysdeps/unix/sysv/linux/ptsname.c
+++ b/sysdeps/unix/sysv/linux/ptsname.c
@@ -72,12 +72,6 @@  __ptsname_internal (int fd, char *buf, size_t buflen, struct stat64 *stp)
   int save_errno = errno;
   unsigned int ptyno;
 
-  if (buf == NULL)
-    {
-      __set_errno (EINVAL);
-      return EINVAL;
-    }
-
   if (!__isatty (fd))
     {
       __set_errno (ENOTTY);