https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96570

--- Comment #18 from Richard Biener <rguenth at gcc dot gnu.org> ---
Cases from code in the wild with desired handling:

  time_t t = time(NULL);
  time_t t2 = 2;
  unsigned int u = 3;
  printf("%i", t); // -Wformat

  int i = t; // warn
  // typical calculation for duration or cache age
  int age = t - t2; // OK? could still cause trouble
  t += t2; // OK
  // typical delay/timeout code:
  t2 = t + i; // OK
  t += i; // OK
  if(t) {t+=1;} // OK
  if(t > i) {} // warn
  if(t < i) {} // warn
  t = i;  // warn
  t = u;  // OK
  u = t;  // OK
  int secs = t % 60; // OK
  int mins = t / 60; // OK


False positives generated from the prototype for:

srand(time(NULL));
time_t += int;
if ( time_t ) {

Reply via email to