refactor: remove ret from secp256k1_ec_pubkey_serialize
What changed, and why it matters
This is a tiny internal code cleanup in a Bitcoin cryptography library. It removes an unnecessary intermediate variable and replaces it with direct 'return 1' and 'return 0' statements. The function's behavior is unchanged, and there is no security issue.
No action required. This is a safe refactoring commit with no security relevance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors secp256k1_ec_pubkey_serialize in src/secp256k1.c. It removes the local ‘int ret = 0;’ variable and changes the success path to ‘return 1;’ and the fall-through to ‘return 0;’. The control flow and return values remain identical to before: the function returns 1 when a valid flag (SECP256K1_EC_COMPRESSED or SECP256K1_EC_UNCOMPRESSED) is provided and serialization succeeds, and 0 otherwise (e.g., invalid flags). No functional or security-relevant change is introduced.
Changed components
src/secp256k1.csecp256k1_ec_pubkey_serializeInspect captured patch +2 / −3
diff --git a/src/secp256k1.c b/src/secp256k1.c
index c2d3fcb..7d6b9bd 100644
--- a/src/secp256k1.c
+++ b/src/secp256k1.c
@@ -268,7 +268,6 @@ int secp256k1_ec_pubkey_parse(const secp256k1_context* ctx, secp256k1_pubkey* pu
int secp256k1_ec_pubkey_serialize(const secp256k1_context* ctx, unsigned char *output, size_t *outputlen, const secp256k1_pubkey* pubkey, unsigned int flags) {
secp256k1_ge Q;
size_t len;
- int ret = 0;
VERIFY_CHECK(ctx != NULL);
ARG_CHECK(outputlen != NULL);
@@ -287,9 +286,9 @@ int secp256k1_ec_pubkey_serialize(const secp256k1_context* ctx, unsigned char *o
secp256k1_eckey_pubkey_serialize65(&Q, output);
*outputlen = 65;
}
- ret = 1;
+ return 1;
}
- return ret;
+ return 0;
}
int secp256k1_ec_pubkey_cmp(const secp256k1_context* ctx, const secp256k1_pubkey* pubkey0, const secp256k1_pubkey* pubkey1) {
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.