RFC Errata

Errata Search

Source of RFC  
Summary Table Full Records

RFC 5905, "Network Time Protocol Version 4: Protocol and Algorithms Specification", June 2010

Source of RFC: ntp (int)

Errata ID: 3404
Status: Held for Document Update
Type: Technical
Publication Format(s) : TEXT

Reported By: Philippe Verdy
Date Reported: 2012-11-08
Held for Document Update by: Brian Haberman

Section A.1.1. says:

#define SQUARE(x)       (x * x)

It should say:

#define SQUARE(x)       ((x) * (x))


This macro is used in the example code to square differences:

//- in clock_filter() {...} (page 85) :

p->jitter += SQUARE(f[i].offset - f[0].offset);

//- in clock_select() { ... } (page 92) :

dtemp += SQUARE(p->offset - q->offset);

//- in clock_combine() { ... } (page 96) :

w += SQUARE(p->offset - s.v[0].p->offset) / x;

//- in local_clock() { ... } (page 99) :

dtemp = SQUARE(max(fabs(offset - c.last),

These expressions are using differences of double values: the .offset member in a Filter stage structure (f), and the .jitter member in an Association structure (p), or in a Local clock structure (c), or in a System structure (s).

All these occurences of macro substitions of SQUARE() will be wrong if the C macro does not surrounds its parameter expression by adding parentheses around them !

This is a very classic error made by beginners in C programming using "utility" macros with side effects... At least newer programmers avoid these kind of macros and prefer defining inline functions

Report New Errata