[gnutls-devel] GnuTLS | lib: use static assertion to check enum values (!1201)

Development of GNU's TLS library gnutls-devel at lists.gnutls.org
Sat Feb 29 17:13:22 CET 2020



Daiki Ueno created a merge request: https://gitlab.com/gnutls/gnutls/-/merge_requests/1201

Branches: tmp-static-assert to master
Author:    Daiki Ueno



We previously had checks of enum values with '#if', such as below:

```c
#define GNUTLS_EXTENSION_MAX_VALUE 31

typedef enum extensions_t {
        ...
        GNUTLS_EXTENSION_MAX /* not real extension - used for iterators */
} extensions_t;

/* we must provide at least 16 extensions for users to register */
#if GNUTLS_EXTENSION_MAX_VALUE - GNUTLS_EXTENSION_MAX < 16
# error not enough extension types
#endif
```

This doesn't work as expected; because `GNUTLS_EXTENSION_MAX` is not
defined as a preprocessor macro, it always expands to 0.  To properly
do this check, we need to use static assert as provided as the
'verify' macro in gnulib.

## Checklist
 * [x] Commits have `Signed-off-by:` with name/author being identical to the commit author
 * [ ] Code modified for feature
 * [ ] Test suite updated with functionality tests
 * [ ] Test suite updated with negative tests
 * [ ] Documentation updated / NEWS entry present (for non-trivial changes)
 * [ ] CI timeout is 2h or higher (see Settings/CICD/General pipelines/Timeout)

## Reviewer's checklist:
 * [ ] Any issues marked for closing are addressed
 * [ ] There is a test suite reasonably covering new functionality or modifications
 * [ ] Function naming, parameters, return values, types, etc., are consistent and according to `CONTRIBUTION.md`
 * [ ] This feature/change has adequate documentation added
 * [ ] No obvious mistakes in the code

-- 
Reply to this email directly or view it on GitLab: https://gitlab.com/gnutls/gnutls/-/merge_requests/1201
You're receiving this email because of your account on gitlab.com.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gnupg.org/pipermail/gnutls-devel/attachments/20200229/88710a88/attachment.html>


More information about the Gnutls-devel mailing list