core: Use flexible array member if compiler has support.
* configure.ac (AC_C_FLEXIBLE_ARRAY_MEMBER): Add. * src/engine-gpg.c (struct arg_and_data_s): Use FLEXIBLE_ARRAY_MEMBER. (_add_arg): Use offsetof instead of sizeof. (add_data): Likewise. -- Before this fix, GCC 11 warns (with its bound checking feature). Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
parent
7cfc93193d
commit
3c1c98a434
@ -543,6 +543,7 @@ AC_CHECK_HEADERS_ONCE([locale.h sys/select.h sys/uio.h argp.h stdint.h
|
|||||||
|
|
||||||
# Type checks.
|
# Type checks.
|
||||||
AC_C_INLINE
|
AC_C_INLINE
|
||||||
|
AC_C_FLEXIBLE_ARRAY_MEMBER
|
||||||
AC_CHECK_SIZEOF(unsigned int)
|
AC_CHECK_SIZEOF(unsigned int)
|
||||||
AC_SYS_LARGEFILE
|
AC_SYS_LARGEFILE
|
||||||
AC_TYPE_OFF_T
|
AC_TYPE_OFF_T
|
||||||
|
@ -59,7 +59,7 @@ struct arg_and_data_s
|
|||||||
int print_fd; /* Print the fd number and not the special form of it. */
|
int print_fd; /* Print the fd number and not the special form of it. */
|
||||||
int *arg_locp; /* Write back the argv idx of this argument when
|
int *arg_locp; /* Write back the argv idx of this argument when
|
||||||
building command line to this location. */
|
building command line to this location. */
|
||||||
char arg[1]; /* Used if data above is not used. */
|
char arg[FLEXIBLE_ARRAY_MEMBER]; /* Used if data above is not used. */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -233,7 +233,7 @@ _add_arg (engine_gpg_t gpg, const char *prefix, const char *arg, size_t arglen,
|
|||||||
assert (gpg);
|
assert (gpg);
|
||||||
assert (arg);
|
assert (arg);
|
||||||
|
|
||||||
a = malloc (sizeof *a + prefixlen + arglen);
|
a = malloc (offsetof (struct arg_and_data_s, arg) + prefixlen + arglen + 1);
|
||||||
if (!a)
|
if (!a)
|
||||||
return gpg_error_from_syserror ();
|
return gpg_error_from_syserror ();
|
||||||
|
|
||||||
@ -307,7 +307,7 @@ add_data (engine_gpg_t gpg, gpgme_data_t data, int dup_to, int inbound)
|
|||||||
assert (gpg);
|
assert (gpg);
|
||||||
assert (data);
|
assert (data);
|
||||||
|
|
||||||
a = malloc (sizeof *a - 1);
|
a = malloc (offsetof (struct arg_and_data_s, arg));
|
||||||
if (!a)
|
if (!a)
|
||||||
return gpg_error_from_syserror ();
|
return gpg_error_from_syserror ();
|
||||||
a->next = NULL;
|
a->next = NULL;
|
||||||
|
Loading…
Reference in New Issue
Block a user