A tale of two data-corruption bugs
A tale of two data-corruption bugs
Posted May 27, 2015 23:00 UTC (Wed) by cesarb (subscriber, #6266)In reply to: A tale of two data-corruption bugs by alankila
Parent article: A tale of two data-corruption bugs
Interestingly, the Rust language does precisely that: macros always have a ! suffix (like format!(...)).
But I agree with the parent comment: making it obvious that it's a macro (all-uppercase, special suffix, etc) would have made no difference. If a programmer sees macro called SECTOR_DIV, receiving a sector number and a sector size, what would the programmer think? "It's a macro which does whatever magic is necessary to divide a sector number by a sector size." The programmer would not expect it to overwrite the sector size passed in! The kernel is full of function-like macros (or functions which are macros in some kernel configurations), no matter how they're named people will expect them to behave like normal functions.
Now suppose the macro had one extra parameter, like "... = SECTOR_DIV(sector, sector, sector_size)". The programmer would question, "why is sector passed twice? Clearly one of them must be an output, or some other arcane trickery; I must look into its definition," and the bug wouldn't happen.
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.
