mirror of
https://github.com/lcn2/calc.git
synced 2025-08-19 01:13:27 +03:00
add NULL pre firewall to ZVALUE code
The z*.c functions that take pointers that cannot be NULL are checked for NULL pointers at the beginning of the function. While calc is not known to pass bogus NULL pointers to ZVALUE related code, libcalc could be called by external code that might do so by mistake. If that happens, math_error() is called with the name of the function and the name of the arg that was NULL.
This commit is contained in:
26
zmul.c
26
zmul.c
@@ -148,6 +148,16 @@ domul(HALF *v1, LEN size1, HALF *v2, LEN size2, HALF *ans)
|
||||
register HALF *hd, *h1=NULL, *h2=NULL; /* for inner loops */
|
||||
SIUNION sival; /* for addition of digits */
|
||||
|
||||
/* firewall */
|
||||
if (v1 == NULL) {
|
||||
math_error("%s: v1 NULL", __func__);
|
||||
not_reached();
|
||||
}
|
||||
if (ans == NULL) {
|
||||
math_error("%s: ans NULL", __func__);
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
* Trim the numbers of leading zeroes and initialize the
|
||||
* estimated size of the result.
|
||||
@@ -651,6 +661,12 @@ zsquare(ZVALUE z, ZVALUE *res)
|
||||
{
|
||||
LEN len;
|
||||
|
||||
/* firewall */
|
||||
if (res == NULL) {
|
||||
math_error("%s: res NULL", __func__);
|
||||
not_reached();
|
||||
}
|
||||
|
||||
if (ziszero(z)) {
|
||||
*res = _zero_;
|
||||
return;
|
||||
@@ -735,6 +751,16 @@ dosquare(HALF *vp, LEN size, HALF *ans)
|
||||
register HALF *hd, *h1, *h2, *h3; /* for inner loops */
|
||||
SIUNION sival; /* for addition of digits */
|
||||
|
||||
/* firewall */
|
||||
if (vp == NULL) {
|
||||
math_error("%s: vp NULL", __func__);
|
||||
not_reached();
|
||||
}
|
||||
if (ans == NULL) {
|
||||
math_error("%s: ans NULL", __func__);
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
* First trim the number of leading zeroes.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user