File: 04-fix-signed-vs-unsigned-comparison

package info (click to toggle)
otpw 1.5-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 444 kB
  • sloc: ansic: 3,862; makefile: 303
file content (37 lines) | stat: -rw-r--r-- 1,327 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
commit 8fc6b3d5f01f6de2d517986330ab4c5896a81d64
Author: Ludovic Stordeur <ludovic@funolang.net>
Date:   Thu Feb 16 11:03:25 2017 +0100

    Fix GCC warning: signed vs unsigned comparison.
    
    The `struct passwd.pw_uid' is typed with `uid_t' which is defined as an
    unsigned integer.
    
    So we now define `otpw_autopseudouser_maxuid' as an `uid_t' as well.
    
    As a result, the comparison of this variable against 0 at otpw.c:124
    can be removed.

diff --git a/otpw.c b/otpw.c
index ba91558..6fc585b 100644
--- a/otpw.c
+++ b/otpw.c
@@ -58,7 +58,7 @@ char *otpw_magic = "OTPW1\n";
 struct otpw_pwdbuf *otpw_pseudouser = NULL;
 
 char *otpw_autopseudouser = "otpw";
-long otpw_autopseudouser_maxuid = 999;
+uid_t otpw_autopseudouser_maxuid = 999;
 
 /* allocate a struct otpw_pwdbuf (of suitable size to also hold the strings) */
 static struct otpw_pwdbuf *otpw_malloc_pwdbuf(void)
@@ -121,8 +121,7 @@ int otpw_set_pseudouser(struct otpw_pwdbuf **pseudouser)
   int err;
   err = otpw_getpwnam(otpw_autopseudouser, pseudouser);
   if (otpw_pseudouser) {
-    if (otpw_autopseudouser_maxuid >= 0 &&
-	otpw_pseudouser->pwd.pw_uid > otpw_autopseudouser_maxuid) {
+    if (otpw_pseudouser->pwd.pw_uid > otpw_autopseudouser_maxuid) {
       err = EINVAL;
       free(*pseudouser);
       otpw_pseudouser = NULL;