Skip to content

Commit fc3ebb0

Browse files
committed
collapse _setException() + return NULL into one statement
1 parent 6f80c7c commit fc3ebb0

File tree

1 file changed

+18
-32
lines changed

1 file changed

+18
-32
lines changed

Modules/_hashopenssl.c

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,8 @@ py_digest_by_name(PyObject *module, const char *name, enum Py_hash_type py_ht)
408408
}
409409
}
410410
if (digest == NULL) {
411-
_setException(state->unsupported_digestmod_error, "unsupported hash type %s", name);
412-
return NULL;
411+
return _setException(state->unsupported_digestmod_error,
412+
"unsupported hash type %s", name);
413413
}
414414
return digest;
415415
}
@@ -530,8 +530,7 @@ EVP_copy_impl(EVPobject *self)
530530

531531
if (!locked_EVP_MD_CTX_copy(newobj->ctx, self)) {
532532
Py_DECREF(newobj);
533-
_setException(PyExc_ValueError, NULL);
534-
return NULL;
533+
return _setException(PyExc_ValueError, NULL);
535534
}
536535
return (PyObject *)newobj;
537536
}
@@ -571,8 +570,7 @@ EVP_digest_impl(EVPobject *self)
571570

572571
error:
573572
EVP_MD_CTX_free(temp_ctx);
574-
_setException(PyExc_ValueError, NULL);
575-
return NULL;
573+
return _setException(PyExc_ValueError, NULL);
576574
}
577575

578576
/*[clinic input]
@@ -610,8 +608,7 @@ EVP_hexdigest_impl(EVPobject *self)
610608

611609
error:
612610
EVP_MD_CTX_free(temp_ctx);
613-
_setException(PyExc_ValueError, NULL);
614-
return NULL;
611+
return _setException(PyExc_ValueError, NULL);
615612
}
616613

617614
/*[clinic input]
@@ -681,8 +678,7 @@ EVP_get_name(EVPobject *self, void *closure)
681678
{
682679
const EVP_MD *md = EVP_MD_CTX_md(self->ctx);
683680
if (md == NULL) {
684-
_setException(PyExc_ValueError, NULL);
685-
return NULL;
681+
return _setException(PyExc_ValueError, NULL);
686682
}
687683
return py_digest_name(md);
688684
}
@@ -796,8 +792,7 @@ EVPXOF_digest_impl(EVPobject *self, Py_ssize_t length)
796792
error:
797793
Py_DECREF(retval);
798794
EVP_MD_CTX_free(temp_ctx);
799-
_setException(PyExc_ValueError, NULL);
800-
return NULL;
795+
return _setException(PyExc_ValueError, NULL);
801796
}
802797

803798
/*[clinic input]
@@ -846,8 +841,7 @@ EVPXOF_hexdigest_impl(EVPobject *self, Py_ssize_t length)
846841
error:
847842
PyMem_Free(digest);
848843
EVP_MD_CTX_free(temp_ctx);
849-
_setException(PyExc_ValueError, NULL);
850-
return NULL;
844+
return _setException(PyExc_ValueError, NULL);
851845
}
852846

853847
static PyMethodDef EVPXOF_methods[] = {
@@ -1445,8 +1439,8 @@ _hashlib_scrypt_impl(PyObject *module, Py_buffer *password, Py_buffer *salt,
14451439
/* let OpenSSL validate the rest */
14461440
retval = EVP_PBE_scrypt(NULL, 0, NULL, 0, n, r, p, maxmem, NULL, 0);
14471441
if (!retval) {
1448-
_setException(PyExc_ValueError, "Invalid parameter combination for n, r, p, maxmem.");
1449-
return NULL;
1442+
return _setException(PyExc_ValueError,
1443+
"Invalid parameter combination for n, r, p, maxmem.");
14501444
}
14511445

14521446
key_obj = PyBytes_FromStringAndSize(NULL, dklen);
@@ -1466,8 +1460,7 @@ _hashlib_scrypt_impl(PyObject *module, Py_buffer *password, Py_buffer *salt,
14661460

14671461
if (!retval) {
14681462
Py_CLEAR(key_obj);
1469-
_setException(PyExc_ValueError, NULL);
1470-
return NULL;
1463+
return _setException(PyExc_ValueError, NULL);
14711464
}
14721465
return key_obj;
14731466
}
@@ -1523,8 +1516,7 @@ _hashlib_hmac_singleshot_impl(PyObject *module, Py_buffer *key,
15231516
PY_EVP_MD_free(evp);
15241517

15251518
if (result == NULL) {
1526-
_setException(PyExc_ValueError, NULL);
1527-
return NULL;
1519+
return _setException(PyExc_ValueError, NULL);
15281520
}
15291521
return PyBytes_FromStringAndSize((const char*)md, md_len);
15301522
}
@@ -1574,8 +1566,7 @@ _hashlib_hmac_new_impl(PyObject *module, Py_buffer *key, PyObject *msg_obj,
15741566
ctx = HMAC_CTX_new();
15751567
if (ctx == NULL) {
15761568
PY_EVP_MD_free(digest);
1577-
_setException(PyExc_ValueError, NULL);
1578-
return NULL;
1569+
return _setException(PyExc_ValueError, NULL);
15791570
}
15801571

15811572
r = HMAC_Init_ex(
@@ -1685,13 +1676,11 @@ _hashlib_HMAC_copy_impl(HMACobject *self)
16851676

16861677
HMAC_CTX *ctx = HMAC_CTX_new();
16871678
if (ctx == NULL) {
1688-
_setException(PyExc_ValueError, NULL);
1689-
return NULL;
1679+
return _setException(PyExc_ValueError, NULL);
16901680
}
16911681
if (!locked_HMAC_CTX_copy(ctx, self)) {
16921682
HMAC_CTX_free(ctx);
1693-
_setException(PyExc_ValueError, NULL);
1694-
return NULL;
1683+
return _setException(PyExc_ValueError, NULL);
16951684
}
16961685

16971686
retval = (HMACobject *)PyObject_New(HMACobject, Py_TYPE(self));
@@ -1719,8 +1708,7 @@ _hmac_repr(HMACobject *self)
17191708
{
17201709
const EVP_MD *md = HMAC_CTX_get_md(self->ctx);
17211710
if (md == NULL) {
1722-
_setException(PyExc_ValueError, NULL);
1723-
return NULL;
1711+
return _setException(PyExc_ValueError, NULL);
17241712
}
17251713
PyObject *digest_name = py_digest_name(md);
17261714
if (digest_name == NULL) {
@@ -1832,8 +1820,7 @@ _hashlib_hmac_get_block_size(HMACobject *self, void *closure)
18321820
{
18331821
const EVP_MD *md = HMAC_CTX_get_md(self->ctx);
18341822
if (md == NULL) {
1835-
_setException(PyExc_ValueError, NULL);
1836-
return NULL;
1823+
return _setException(PyExc_ValueError, NULL);
18371824
}
18381825
return PyLong_FromLong(EVP_MD_block_size(md));
18391826
}
@@ -1843,8 +1830,7 @@ _hashlib_hmac_get_name(HMACobject *self, void *closure)
18431830
{
18441831
const EVP_MD *md = HMAC_CTX_get_md(self->ctx);
18451832
if (md == NULL) {
1846-
_setException(PyExc_ValueError, NULL);
1847-
return NULL;
1833+
return _setException(PyExc_ValueError, NULL);
18481834
}
18491835
PyObject *digest_name = py_digest_name(md);
18501836
if (digest_name == NULL) {

0 commit comments

Comments
 (0)