From f04242f2c50752860525eda574df56a770855a54 Mon Sep 17 00:00:00 2001 From: Arne Goedeke <el@laramies.com> Date: Thu, 13 Nov 2014 15:46:04 +0100 Subject: [PATCH] Strings: silence a warning Using a function instead of a macro takes care of casting the first argument to a signed type, which silences a warning when the macro was used with unsigned types. --- src/stralloc.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/stralloc.h b/src/stralloc.h index 164546c42b..11032b9566 100644 --- a/src/stralloc.h +++ b/src/stralloc.h @@ -144,10 +144,17 @@ PMOD_EXPORT p_wchar2 index_shared_string(const struct pike_string *s, ptrdiff_t /* arithmetic left shift. compilers will understand this * and generate one arithmetic left shift. Left shifting - * a negative integer is undefined and could be optimized - * away by compilers. + * a negative integer is implementation defined and + * not all compilers do arithmetic left shifts. */ -#define SAL(a, b) ((a) < 0 ? -(-(a) << (b)) : (a) << (b)) +__attribute__((unused)) +static INLINE ptrdiff_t SAL(ptrdiff_t a, unsigned int b) { + if (a < 0) { + return -(-a << b); + } else { + return a << b; + } +} #define EXTRACT_CHARP(PTR,SHIFT) INDEX_CHARP((PTR),0,(SHIFT)) #define CHARP_ADD(PTR,X,SHIFT) (PTR)+=SAL(X,SHIFT) -- GitLab