compiler indepenedent sign-extended signed right shift macroes

git-svn: trunk@3126
remotes/push_mirror/metadata
aCaB 18 years ago
parent e1a2e45704
commit 35eb635417
  1. 5
      ChangeLog
  2. 3
      clamav-config.h.in
  3. 57
      configure
  4. 12
      configure.in
  5. 8
      libclamav/others.h
  6. 2
      libclamav/unsp.c
  7. 2
      libclamav/upack.c
  8. 4
      libclamav/upx.c

@ -1,3 +1,8 @@
Sun Jul 8 17:25:04 CEST 2007 (acab)
------------------------------------
* misc: Implement compiler indepenedent sign-extended signed right shift
when needed - reported by Michal Spadlinski <gim913 * gmail.com>
Sat Jul 07 10:52:00 CEST 2007 (edwin)
----------------------------------
* libclamav/phishcheck.c: fix typo in regex

@ -216,6 +216,9 @@
/* have resolv.h */
#undef HAVE_RESOLV_H
/* Define signed right shift implementation */
#undef HAVE_SAR
/* Define to 1 if you have the `sendmsg' function. */
#undef HAVE_SENDMSG

57
configure vendored

@ -25852,6 +25852,63 @@ cat >>confdefs.h <<_ACEOF
_ACEOF
{ echo "$as_me:$LINENO: checking if signed right shift is sign extended" >&5
echo $ECHO_N "checking if signed right shift is sign extended... $ECHO_C" >&6; }
if test "$cross_compiling" = yes; then
have_signed_rightshift_extended=no
else
cat >conftest.$ac_ext <<_ACEOF
/* confdefs.h. */
_ACEOF
cat confdefs.h >>conftest.$ac_ext
cat >>conftest.$ac_ext <<_ACEOF
/* end confdefs.h. */
int main(void){int a=-1;int b=a>>1;return(a!=b);}
_ACEOF
rm -f conftest$ac_exeext
if { (ac_try="$ac_link"
case "(($ac_try" in
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
*) ac_try_echo=$ac_try;;
esac
eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
(eval "$ac_link") 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } && { ac_try='./conftest$ac_exeext'
{ (case "(($ac_try" in
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
*) ac_try_echo=$ac_try;;
esac
eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
(eval "$ac_try") 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; }; then
have_signed_rightshift_extended=yes
else
echo "$as_me: program exited with status $ac_status" >&5
echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
( exit $ac_status )
have_signed_rightshift_extended=no
fi
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
fi
if test $have_signed_rightshift_extended = yes; then
cat >>confdefs.h <<\_ACEOF
#define HAVE_SAR 1
_ACEOF
fi
{ echo "$as_me:$LINENO: result: $have_signed_rightshift_extended" >&5
echo "${ECHO_T}$have_signed_rightshift_extended" >&6; };
ac_config_files="$ac_config_files libclamav/Makefile clamscan/Makefile database/Makefile docs/Makefile clamd/Makefile clamdscan/Makefile clamav-milter/Makefile freshclam/Makefile sigtool/Makefile clamconf/Makefile etc/Makefile Makefile clamav-config libclamav.pc docs/man/clamav-milter.8 docs/man/clamconf.1 docs/man/clamd.8 docs/man/clamd.conf.5 docs/man/clamdscan.1 docs/man/clamscan.1 docs/man/freshclam.1 docs/man/freshclam.conf.5 docs/man/sigtool.1"
cat >confcache <<\_ACEOF

@ -1059,6 +1059,18 @@ DEFAULT_FD_SETSIZE=256)
AC_MSG_RESULT($DEFAULT_FD_SETSIZE)
AC_DEFINE_UNQUOTED(DEFAULT_FD_SETSIZE, $DEFAULT_FD_SETSIZE, "default FD_SETSIZE value")
dnl Check signed right shift implementation
AC_MSG_CHECKING(if signed right shift is sign extended)
AC_TRY_RUN([int main(void){int a=-1;int b=a>>1;return(a!=b);}],
[have_signed_rightshift_extended=yes],
[have_signed_rightshift_extended=no],
[have_signed_rightshift_extended=no])
if test $have_signed_rightshift_extended = yes; then
AC_DEFINE(HAVE_SAR, 1, Define signed right shift implementation)
fi
AC_MSG_RESULT($have_signed_rightshift_extended);
AC_OUTPUT([
libclamav/Makefile
clamscan/Makefile

@ -132,6 +132,14 @@ typedef struct {
#define ROL(a,b) a = ( a << (b % (sizeof(a)<<3) )) | (a >> ( (sizeof(a)<<3) - (b % (sizeof(a)<<3 )) ) )
#define ROR(a,b) a = ( a >> (b % (sizeof(a)<<3) )) | (a << ( (sizeof(a)<<3) - (b % (sizeof(a)<<3 )) ) )
/* Implementation independent sign-extended signed right shift */
#ifdef HAVE_SAR
#define SRS(n,s) ((n)>>(s))
#else
#define SRS(n,s) (((n)>>(s)) ^ (1<<(sizeof(n)*8-1-s)) - (1<<(sizeof(n)*8-1-s)))
#endif
#define SAR(n,s) n = SRS(n,s)
#ifndef FALSE
#define FALSE (0)
#endif

@ -400,7 +400,7 @@ int getbit_from_table(uint16_t *intable, struct UNSP *read_struct) {
read_struct->bitmap = nval;
nval = *intable;
sval = 0x800 - nval;
sval = ((int32_t)sval)>>5; /* signed */
sval = SRS((int32_t)sval,5); /* signed */
sval += nval;
*intable=sval;
if (read_struct->bitmap<0x1000000) { /* unsigned */

@ -543,7 +543,7 @@ int unupack399(char *bs, uint32_t bl, uint32_t init_eax, char *init_ebx, uint32_
return -1;
/* cdq, loc_edx = (loc_eax&0x80000000)?0xffffffff:0; */
loc_ecx = temp_ebp;
temp_ebp = (int32_t)loc_eax >> 31; /* thx, desp */
temp_ebp = SRS((int32_t)loc_eax, 31); /* thx, desp */
/* loc_483a00 */
do {
temp_ebp += temp_ebp;

@ -394,7 +394,7 @@ int upx_inflate2d(char *src, uint32_t ssize, char *dst, uint32_t *dsize, uint32_
if (!backbytes)
break;
backsize = backbytes & 1;
backbytes>>=1;
SAR(backbytes,1);
unp_offset = backbytes;
} else {
if ( (backsize = (uint32_t)doubleebx(src, &myebx, &scur, ssize)) == 0xffffffff )
@ -474,7 +474,7 @@ int upx_inflate2e(char *src, uint32_t ssize, char *dst, uint32_t *dsize, uint32_
if (!backbytes)
break;
backsize = backbytes & 1; /* Using backsize to carry on the shifted out bit (UPX uses CF) */
backbytes>>=1;
SAR(backbytes,1);
unp_offset = backbytes;
} else {
if ( (backsize = (uint32_t)doubleebx(src, &myebx, &scur, ssize)) == 0xffffffff )

Loading…
Cancel
Save