mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-07-28 01:41:48 +03:00
buffer: Fix regression introduced by 6c7eaa and c306a6
Buffer (un)packing was broken on compilers that are not gcc-compatible since the checks for an argument count of -1 have been removed from ssh_buffer_(un)pack(). This fix no longer uses GCC extensions for the __VA_NARG__ macro, but only plain C99. Note: The macro can no longer count empty argument lists (results in compile error) which was not needed anyway. Signed-off-by: Tilo Eckert <tilo.eckert@flam.de> Reviewed-by: Andreas Schneider <asn@cryptomilk.org> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
This commit is contained in:
committed by
Andreas Schneider
parent
5a590dfb5f
commit
7caf6d2ab6
@ -379,18 +379,6 @@ int main(void)
|
|||||||
return 0;
|
return 0;
|
||||||
}" HAVE_GCC_VOLATILE_MEMORY_PROTECTION)
|
}" HAVE_GCC_VOLATILE_MEMORY_PROTECTION)
|
||||||
|
|
||||||
check_c_source_compiles("
|
|
||||||
#include <stdio.h>
|
|
||||||
#define __VA_NARG__(...) (__VA_NARG_(_0, ## __VA_ARGS__, __RSEQ_N()) - 1)
|
|
||||||
#define __VA_NARG_(...) __VA_ARG_N(__VA_ARGS__)
|
|
||||||
#define __VA_ARG_N( _1, _2, _3, _4, _5, _6, _7, _8, _9,_10,N,...) N
|
|
||||||
#define __RSEQ_N() 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
|
|
||||||
#define myprintf(format, ...) printf((format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__)
|
|
||||||
int main(void) {
|
|
||||||
myprintf(\"%d %d %d %d\",1,2,3);
|
|
||||||
return 0;
|
|
||||||
}" HAVE_GCC_NARG_MACRO)
|
|
||||||
|
|
||||||
check_c_source_compiles("
|
check_c_source_compiles("
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
int main(void) {
|
int main(void) {
|
||||||
|
@ -219,7 +219,6 @@
|
|||||||
#cmakedefine HAVE_DESTRUCTOR_ATTRIBUTE 1
|
#cmakedefine HAVE_DESTRUCTOR_ATTRIBUTE 1
|
||||||
|
|
||||||
#cmakedefine HAVE_GCC_VOLATILE_MEMORY_PROTECTION 1
|
#cmakedefine HAVE_GCC_VOLATILE_MEMORY_PROTECTION 1
|
||||||
#cmakedefine HAVE_GCC_NARG_MACRO 1
|
|
||||||
|
|
||||||
#cmakedefine HAVE_COMPILER__FUNC__ 1
|
#cmakedefine HAVE_COMPILER__FUNC__ 1
|
||||||
#cmakedefine HAVE_COMPILER__FUNCTION__ 1
|
#cmakedefine HAVE_COMPILER__FUNCTION__ 1
|
||||||
|
@ -328,7 +328,6 @@ void explicit_bzero(void *s, size_t n);
|
|||||||
/**
|
/**
|
||||||
* Get the argument cound of variadic arguments
|
* Get the argument cound of variadic arguments
|
||||||
*/
|
*/
|
||||||
#ifdef HAVE_GCC_NARG_MACRO
|
|
||||||
/*
|
/*
|
||||||
* Since MSVC 2010 there is a bug in passing __VA_ARGS__ to subsequent
|
* Since MSVC 2010 there is a bug in passing __VA_ARGS__ to subsequent
|
||||||
* macros as a single token, which results in:
|
* macros as a single token, which results in:
|
||||||
@ -338,7 +337,7 @@ void explicit_bzero(void *s, size_t n);
|
|||||||
#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
|
#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
|
||||||
|
|
||||||
#define __VA_NARG__(...) \
|
#define __VA_NARG__(...) \
|
||||||
(__VA_NARG_(_0, ## __VA_ARGS__, __RSEQ_N()) - 1)
|
(__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
|
||||||
#define __VA_NARG_(...) \
|
#define __VA_NARG_(...) \
|
||||||
VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
|
VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
|
||||||
#define __VA_ARG_N( \
|
#define __VA_ARG_N( \
|
||||||
@ -357,10 +356,6 @@ void explicit_bzero(void *s, size_t n);
|
|||||||
29, 28, 27, 26, 25, 24, 23, 22, 21, 20, \
|
29, 28, 27, 26, 25, 24, 23, 22, 21, 20, \
|
||||||
19, 18, 17, 16, 15, 14, 13, 12, 11, 10, \
|
19, 18, 17, 16, 15, 14, 13, 12, 11, 10, \
|
||||||
9, 8, 7, 6, 5, 4, 3, 2, 1, 0
|
9, 8, 7, 6, 5, 4, 3, 2, 1, 0
|
||||||
#else
|
|
||||||
/* clang does not support the above construction */
|
|
||||||
#define __VA_NARG__(...) (-1)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define CLOSE_SOCKET(s) do { if ((s) != SSH_INVALID_SOCKET) { _XCLOSESOCKET(s); (s) = SSH_INVALID_SOCKET;} } while(0)
|
#define CLOSE_SOCKET(s) do { if ((s) != SSH_INVALID_SOCKET) { _XCLOSESOCKET(s); (s) = SSH_INVALID_SOCKET;} } while(0)
|
||||||
|
|
||||||
|
@ -245,10 +245,8 @@ static void torture_buffer_pack_badformat(void **state){
|
|||||||
|
|
||||||
/* with additional format */
|
/* with additional format */
|
||||||
rc = ssh_buffer_pack(buffer, "bb", b);
|
rc = ssh_buffer_pack(buffer, "bb", b);
|
||||||
#ifdef HAVE_GCC_NARG_MACRO
|
/* check that we detect the missing parameter */
|
||||||
/* We can only detect errors if we have support for NARG macros */
|
|
||||||
assert_int_equal(rc, SSH_ERROR);
|
assert_int_equal(rc, SSH_ERROR);
|
||||||
#endif
|
|
||||||
|
|
||||||
/* unpack with missing format */
|
/* unpack with missing format */
|
||||||
ssh_buffer_reinit(buffer);
|
ssh_buffer_reinit(buffer);
|
||||||
|
@ -496,10 +496,8 @@ static void *thread_buffer_pack_badformat(void *threadid)
|
|||||||
|
|
||||||
/* with additional format */
|
/* with additional format */
|
||||||
rc = ssh_buffer_pack(buffer, "bb", b);
|
rc = ssh_buffer_pack(buffer, "bb", b);
|
||||||
#ifdef HAVE_GCC_NARG_MACRO
|
/* check that we detect the missing parameter */
|
||||||
/* We can only detect errors if we have support for NARG macros */
|
|
||||||
assert_int_equal(rc, SSH_ERROR);
|
assert_int_equal(rc, SSH_ERROR);
|
||||||
#endif
|
|
||||||
|
|
||||||
/* unpack with missing format */
|
/* unpack with missing format */
|
||||||
ssh_buffer_reinit(buffer);
|
ssh_buffer_reinit(buffer);
|
||||||
|
Reference in New Issue
Block a user