Instead of checking for overflow and zero manually, use the existing _scalar_set_b32_seckey helper which does both and returns zero if either of these two conditions apply. This can be seen as a very late follow-up to PR #701, commit 3fec9826086aa45ebbac1ff6fc3bb7b25ca78b1d, where the helper has been introduced and applied to the functions _ecdsa_sign, _pubkey_create and _seckey_verify. The variable name is_sec_valid has been chosen as it is currently also used in secp256k1_ecdsa_sign_inner.
Note that introducing parantheses around !!ret was necessary to avoid warnings in the following form:
/home/thestack/secp256k1_master/src/modules/ecdh/main_impl.h: In function ‘secp256k1_ecdh’:
/home/thestack/secp256k1_master/src/modules/ecdh/main_impl.h:74:12: warning: suggest parentheses around operand of ‘!’ or change ‘&’ to ‘&&’ or ‘
!’ to ‘~’ [-Wparentheses]
74 | return !!ret & is_sec_valid;
| ^~~~~