[review] login: Remove double-assignment of fl.l_whence in try_file_lock
diff mbox series

Message ID gerrit.1573077292000.I2baf9e70690e723c61051b25ccbd510aec15976c@gnutoolchain-gerrit.osci.io
State New
Headers show
Series
  • [review] login: Remove double-assignment of fl.l_whence in try_file_lock
Related show

Commit Message

Carlos O'Donell (Code Review) Nov. 6, 2019, 9:54 p.m. UTC
Change URL: https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/515
......................................................................

login: Remove double-assignment of fl.l_whence in try_file_lock

Since l_whence is the second member of struct flock, it is written
twice.  The double-assignment is technically undefined behavior due to
the lack of a sequence point.

Change-Id: I2baf9e70690e723c61051b25ccbd510aec15976c
---
M login/utmp_file.c
1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Carlos O'Donell (Code Review) Nov. 6, 2019, 9:56 p.m. UTC | #1
Carlos O'Donell has posted comments on this change.

Change URL: https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/515
......................................................................


Patch Set 1: Code-Review+2

(1 comment)

https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/515/1/login/utmp_file.c 
File login/utmp_file.c:

https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/515/1/login/utmp_file.c@82 
PS1, Line 82: 
63 | try_file_lock (int fd, int type)
   | ...
77 | 
78 |   /* Try to get the lock.  */
79 |  struct flock64 fl =
80 |    {
81 |     .l_type = type,
82 >     .l_whence = SEEK_SET,
83 |    };
84 | 
85 |  bool status = __fcntl64_nocancel (fd, F_SETLKW, &fl) < 0;
86 |  int saved_errno = errno;
87 | 

OK. The double assignment is that we used 'fl' in the orignal code. This fix is correct.
Carlos O'Donell (Code Review) Nov. 6, 2019, 9:57 p.m. UTC | #2
Carlos O'Donell has posted comments on this change.

Change URL: https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/515
......................................................................


Patch Set 1:

OK for master. Totally a typo. I'd say this is almost a trivial bug fix not requiring a review, but I'm happy to review it.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>

Patch
diff mbox series

diff --git a/login/utmp_file.c b/login/utmp_file.c
index be7cc06..e627233 100644
--- a/login/utmp_file.c
+++ b/login/utmp_file.c
@@ -79,7 +79,7 @@ 
  struct flock64 fl =
    {
     .l_type = type,
-    fl.l_whence = SEEK_SET,
+    .l_whence = SEEK_SET,
    };
 
  bool status = __fcntl64_nocancel (fd, F_SETLKW, &fl) < 0;