Code

RRTimeslice: Don't encode invalid (0) intervals in the output function.
authorSebastian Harl <sh@tokkee.org>
Tue, 30 Oct 2012 06:24:02 +0000 (07:24 +0100)
committerSebastian Harl <sh@tokkee.org>
Tue, 30 Oct 2012 06:24:02 +0000 (07:24 +0100)
src/rrtimeslice.c

index 325d736fe3e90bf35a72108a2ae8c80a1579ffd8..4f151d27b1b3f93b60164bc9759ddfb718396b46 100644 (file)
@@ -330,8 +330,6 @@ rrtimeslice_out(PG_FUNCTION_ARGS)
 {
        rrtimeslice_t *tslice;
 
-       Interval interval;
-
        struct pg_tm tm;
        fsec_t fsec = 0;
        int tz = 0;
@@ -364,6 +362,8 @@ rrtimeslice_out(PG_FUNCTION_ARGS)
                EncodeDateTime(&tm, fsec, &tz, &tz_str, DateStyle, buf_ts);
 
        if (! rrtimeslice_get_spec(tslice->tsid, &len, &num)) {
+               Interval interval;
+
                memset(&interval, 0, sizeof(interval));
                interval.time = len * USECS_PER_SEC;
                fsec = 0;
@@ -372,14 +372,14 @@ rrtimeslice_out(PG_FUNCTION_ARGS)
                        ereport(ERROR, (
                                                errmsg("could not convert interval to tm")
                                        ));
+
+               EncodeInterval(&tm, fsec, IntervalStyle, buf_l);
        }
        else {
                strncpy(buf_l, "ERR", sizeof(buf_l));
                buf_l[sizeof(buf_l) - 1] = '\0';
        }
 
-       EncodeInterval(&tm, fsec, IntervalStyle, buf_l);
-
        snprintf(ts_str, sizeof(ts_str), "%s -%s (#%i)",
                        buf_ts, buf_l, tslice->seq);