Consequences of passing too few register parameters to a C function
The article discusses the implications of passing too few parameters to a C function. It highlights that such actions can lead to undefined behavior, including potential memory corruption. Special cases, such as those involving Itanium architecture, are also examined for their unique handling of uninitialized registers.
- ▪Passing too few parameters to a C function can result in undefined behavior.
- ▪If a function is called with insufficient parameters, it may lead to stack imbalance and memory corruption.
- ▪On Itanium processors, uninitialized registers can cause exceptions due to the NaT bit.
Opening excerpt (first ~120 words) tap to expand
In our exploration of calling conventions for various processors on Windows, we learned that in many cases, some of the parameters are passed in registers. Suppose that there is a function that takes two parameters, but you know that the function ignores the second parameter if the first parameter is positive. What happens if you call the function with just one parameter (say, passing zero). The function should ignore the second parameter, so why does it matter that you didn’t pass one? Even though the function doesn’t use the parameter, it still may decide to use the storage for that parameter as a conveniently provided scratch space.
…
Excerpt limited to ~120 words for fair-use compliance. The full article is at The Old New Thing.