|
|
Log in / Subscribe / Register

Fixing sector_div

Fixing sector_div

Posted May 25, 2015 12:57 UTC (Mon) by jreiser (subscriber, #11027)
In reply to: A tale of two data-corruption bugs by cesarb
Parent article: A tale of two data-corruption bugs

The best fix from the viewpoint of safety and reliability is two new static functions sector_quo and sector_rem, along with changing the definition of macro sector_div so that its expansion causes a compile-time error which refers the programmer to sector_quo and sector_rem.

Even then, we are not done yet. There must be an audit to detect and evaluate all similar instances: any macro with arguments that is not equivalent to the obvious C-language function of those same arguments. There are valid uses of such macros, but they must be prominently documented because of the high risk of confusion with functions. Among other checks: correct use of parentheses, brackets and braces "()[]{}"; no use of any argument as an lvalue; no use of any identifier which is not in scope at time of definition. Automate the detection phase of the audit using help from your favorite shell, editor and compiler.


The LWN site is currently under high scraper load, so comment display has been suppressed for anonymous users. If you are a human, you may read the comments by clicking the button below:

Note: you can avoid this step in the future by logging into your LWN account.


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds