"n must be a non-negative integer");
goto error;
}
+ if (Py_SIZE(k) < 0) {
+ PyErr_SetString(PyExc_ValueError,
+ "k must be a non-negative integer");
+ goto error;
+ }
+
cmp = PyObject_RichCompareBool(n, k, Py_LT);
if (cmp != 0) {
if (cmp > 0) {
LLONG_MAX);
goto error;
}
- else if (overflow < 0 || factors < 0) {
- if (!PyErr_Occurred()) {
- PyErr_SetString(PyExc_ValueError,
- "k must be a non-negative integer");
- }
+ else if (factors == -1) {
+ /* k is nonnegative, so a return value of -1 can only indicate error */
goto error;
}
"n must be a non-negative integer");
goto error;
}
+ if (Py_SIZE(k) < 0) {
+ PyErr_SetString(PyExc_ValueError,
+ "k must be a non-negative integer");
+ goto error;
+ }
+
/* k = min(k, n - k) */
temp = PyNumber_Subtract(n, k);
if (temp == NULL) {
LLONG_MAX);
goto error;
}
- else if (overflow < 0 || factors < 0) {
- if (!PyErr_Occurred()) {
- PyErr_SetString(PyExc_ValueError,
- "k must be a non-negative integer");
- }
+ if (factors == -1) {
+ /* k is nonnegative, so a return value of -1 can only indicate error */
goto error;
}