FLTK logo

Re: [fltk/fltk] Scaled window dimensions off by 1 (#123)

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.issues  ]
 
Previous Message ]New Message | Reply ]Next Message ]

Re: [fltk/fltk] Scaled window dimensions off by 1 (#123) Albrecht Schlosser Nov 26, 2020  
 

I've seen warnings in static code analyzers that really surprised me. They can check many, many cases, some of which are maybe "impossible" to be true (for human thinking) but the code analyzers still find a case ...

Manolo is correct about evaluation of logical && and || in expressions in C and C++. A usual case is if (win && win->x() < 0);. This construct is only useful if the evaluation is guaranteed to be terminated if win == NULL (and it is).

However, in that particular case (see @erco77's screenshot) I believe the point is that the compiler doesn't "know" that Fl::screen_xyhw() always returns a value in sx, sy, sw, and sh (if this is not the case for instance if the screen number is out or range then this IS a fault). I've seen this in similar constructs with values returned by reference arguments. In this case the first sx *= s; statement would access an uninitialized variable if win != NULL.

It's probably wise to initialize these variables with 0 (zero) even if it's not really necessary (defensive programming).


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.