diff --git a/Sex-field-notes.org b/Sex-field-notes.org index 1afe466..e287ef6 100644 --- a/Sex-field-notes.org +++ b/Sex-field-notes.org @@ -42,6 +42,24 @@ Clang only warns (-Wparentheses). This one computes wrong values silently, so it is the most dangerous entry here. Bound to a variable first, it's right. +Clang warns only when the operator ends up in the condition, as above. +When the conditional comes first, the rest of the operand moves into +the else branch, and that is valid C nothing warns about. A sweep of +this project found four such sites that had compiled cleanly with +-Wall -Wparentheses: +- =(malloc (* (if (> w h) w h) (sizeof u32)))= emitted + =malloc((w > h) ? w : h * sizeof(u32))=: when =w > h=, a buffer a + quarter of the size, so a heap overflow on every wide box blur. +- =(+ (if (< d -4) -4 (if (> d 4) 4 d)) 4)= gave an index of -4, an + out-of-bounds write that corrupted a neighbouring array of counts + and with it a figure in our own docs. +- =(* (if (> depth 40) 40 depth) 255)= gave water deeper than 40 blocks + the shallow colour. +- =(cast (if ...) float)= cast only the condition; harmless there. + +Only the generated C showed them. The fix is the same: bind to a +variable first. + * An import doesn't bring the types its interface needs Module =save= takes a =(* region-maps)= from module =maps=. Importing =save= pastes its prototypes but not =region-maps=, so every importer