Re: [chrony-dev] GCC issue

[ Thread Index | Date Index | More chrony.tuxfamily.org/chrony-dev Archives ]


No, that does the same thing as your previous suggestion-- it closes "out"
only if it fails, whereas you want to close "out" always, but issue an error
message if out does not close or if the print fails for whatever reason

{boolean pflag,cflag;
pflag=(fprintf(out, "%20.6f %20.6f\n", freq_ppm, 1.0e6 * skew) < 0);
cflag=fclose(out);
if(plag||cflag) {
    Free(temp_drift_file);
     LOG(LOGS_WARN, LOGF_Reference, "Could not write to temporary
 driftfile %s.tmp",
         drift_file);
     return;
}

Assuming optimisation did not collapse this down to your original suggestion.

The question is-- which is the original bitwise or failing?

Note that you could also do something like

 if ((fprintf(out, "%20.6f %20.6f\n", freq_ppm, 1.0e6 * skew) < 0) |
      (fclose(out)!=0)) {
making sure that on failure the bitwise or had the same thing to work with.



On Tue, 21 Jan 2014, Harald Krammer wrote:

You are right.


Index: src/chrony/reference.c
===================================================================
--- chrony/reference.c
+++ chrony/reference.c
@@ -311,14 +311,16 @@
  }

  /* Write the frequency and skew parameters in ppm */
-  if ((fprintf(out, "%20.6f %20.6f\n", freq_ppm, 1.0e6 * skew) < 0) |
-      fclose(out)) {
+  if ( fprintf(out, "%20.6f %20.6f\n", freq_ppm, 1.0e6 * skew) < 0)  {
+    fclose(out);
    Free(temp_drift_file);
    LOG(LOGS_WARN, LOGF_Reference, "Could not write to temporary
driftfile %s.tmp",
        drift_file);
    return;
  }

+  fclose(out);
+
  /* Clone the file attributes from the existing file if there is one. */

  if (!stat(drift_file,&buf)) {




On Tue, 21 Jan 2014 10:39:43 +0100, Håkan Johansson <f96hajo@xxxxxxxxxxx>
wrote:
With a logical or, the fclose will not happen if fprintf fails.
Perhaps better separate these calls?

// Håkan


On Tue, 21 Jan 2014, Harald Krammer wrote:

Hello,

I am testing Chrony 1.29 on my ARM based System with GCC 3.4.6.

A small problem is happen in reference.c.  GCC 3.4.6 does not respect
the order in bit-wise or.  -> fclose comes for fprintf
-> a logical or works fine


Index: chrony/reference.c
===================================================================
--- chrony/reference.c
+++ chrony/reference.c
@@ -311,7 +311,7 @@
  }

  /* Write the frequency and skew parameters in ppm */
-  if ((fprintf(out, "%20.6f %20.6f\n", freq_ppm, 1.0e6 * skew) < 0) |
+  if ((fprintf(out, "%20.6f %20.6f\n", freq_ppm, 1.0e6 * skew) < 0) ||
      fclose(out)) {
    Free(temp_drift_file);
    LOG(LOGS_WARN, LOGF_Reference, "Could not write to temporary
driftfile %s.tmp",



Nice greetings,
Harald Krammer


--
To unsubscribe email chrony-dev-request@xxxxxxxxxxxxxxxxxxxx with
"unsubscribe" in the subject.
For help email chrony-dev-request@xxxxxxxxxxxxxxxxxxxx with "help" in
the subject.
Trouble?  Email listmaster@xxxxxxxxxxxxxxxxxxxx.



--
To unsubscribe email chrony-dev-request@xxxxxxxxxxxxxxxxxxxx with "unsubscribe" in the subject.
For help email chrony-dev-request@xxxxxxxxxxxxxxxxxxxx with "help" in the subject.
Trouble?  Email listmaster@xxxxxxxxxxxxxxxxxxxx.


--
William G. Unruh   |  Canadian Institute for|     Tel: +1(604)822-3273
Physics&Astronomy  |     Advanced Research  |     Fax: +1(604)822-5324
UBC, Vancouver,BC  |   Program in Cosmology |     unruh@xxxxxxxxxxxxxx
Canada V6T 1Z1     |      and Gravity       |  www.theory.physics.ubc.ca/


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/