commit c9609ea5ff66f226a2829ab4e00d2b2f8212e3b8
parent 3669fa411773c56044b0e9027fdcc6290631a173
Author: sin <sin@2f30.org>
Date: Wed, 2 Jul 2014 12:03:01 +0100
Only call fwrite() and fclose() when fp is not NULL
Spotted by Hiltjo.
Diffstat:
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/login.c b/login.c
@@ -89,12 +89,14 @@ main(int argc, char *argv[])
usr.ut_tv.tv_sec = time(NULL);
fp = fopen(UTMP_PATH, "a");
- if (!fp)
+ if (fp) {
+ if (fwrite(&usr, sizeof(usr), 1, fp) != 1)
+ if (ferror(fp))
+ weprintf("%s: write error:", UTMP_PATH);
+ fclose(fp);
+ } else {
weprintf("fopen %s:", UTMP_PATH);
- if (fwrite(&usr, sizeof(usr), 1, fp) != 1)
- if (ferror(fp))
- weprintf("%s: write error:", UTMP_PATH);
- fclose(fp);
+ }
return dologin(pw, pflag);
}