From e33f078c051ca43d98c3bfa12c94e6281fd4d888 Mon Sep 17 00:00:00 2001 From: millert <> Date: Tue, 29 Dec 2015 18:23:28 +0000 Subject: [PATCH] Don't assume fprintf() will set the FILE * error condition. Instead, check the return value of fprintf() and fflush() and call clearerr() before returning on error. OK jca@ --- src/usr.sbin/ntpd/ntpd.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/usr.sbin/ntpd/ntpd.c b/src/usr.sbin/ntpd/ntpd.c index cf88fe87..a763905e 100644 --- a/src/usr.sbin/ntpd/ntpd.c +++ b/src/usr.sbin/ntpd/ntpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ntpd.c,v 1.101 2015/12/19 17:55:29 reyk Exp $ */ +/* $OpenBSD: ntpd.c,v 1.102 2015/12/29 18:23:28 millert Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -552,13 +552,13 @@ writefreq(double d) if (freqfp == NULL) return 0; rewind(freqfp); - fprintf(freqfp, "%.3f\n", d * 1e6); /* scale to ppm */ - r = ferror(freqfp); - if (r != 0) { + r = fprintf(freqfp, "%.3f\n", d * 1e6); /* scale to ppm */ + if (r < 0 || fflush(freqfp) != 0) { if (warnonce) { log_warnx("can't write %s", DRIFTFILE); warnonce = 0; } + clearerr(freqfp); return 0; } ftruncate(fileno(freqfp), ftello(freqfp));