Hi, Support,

I've found the strange behavior in the rtree.c file.
I think that in the  static int writeInt64(u8 *p, i64 i) function.

static int writeInt64(u8 *p, i64 i){
#if SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000
  i = (i64)__builtin_bswap64((u64)i);
  memcpy(p, &i, 8);
#elif SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300
  i = (i64)_byteswap_uint64((u64)i);
  memcpy(p, &i, 8);
#elif SQLITE_BYTEORDER==4321
  memcpy(p, &i, 8);
#else
  p[0] = (i>>56)&0xFF;
  p[1] = (i>>48)&0xFF;
  p[2] = (i>>40)&0xFF;
  p[3] = (i>>32)&0xFF;
  p[4] = (i>>24)&0xFF;
  p[5] = (i>>16)&0xFF;
  p[6] = (i>> 8)&0xFF;
  p[7] = (i>> 0)&0xFF;
#endif
  return 8;
}

If I build the SQLite with option 'Compile as C Code (/TC)' I've got the 
warning warning C4013: '_byteswap_uint64' undefined; assuming extern returning 
int

The highlighted line of function works incorrectly if #include <stdlib.h> is 
missed. For example, it returns 0 value if i=1000 was passed into the function 
_byteswap_uint64.

Steps to reproduce:

  1.  Create console application in Visual Studio. The source code is below.
#include "stdafx.h"
//#include <stdlib.h>

static __int64 writeInt64(char *p, __int64 i) {
       i = (__int64)_byteswap_uint64((unsigned __int64)i);
       memcpy(p, &i, 8);

       return 8;
}

int main()
{
       unsigned __int64 i = 1000;
       char buff[8] = { 0, };
       i = writeInt64(buff, i);
       return 0;
}


  1.  Build it with the option 'Compile as C Code (/TC)'
  2.  Set breakpoint on the i = (__int64)_byteswap_uint64((unsigned __int64)i);
  3.  Run it and call 'Go to Disassembled'
w/o #include <stdlib.h>
i = (__int64)_byteswap_uint64((unsigned __int64)i);
008F17CE  mov         eax,dword ptr [ebp+10h]
008F17D1  push        eax
008F17D2  mov         ecx,dword ptr [i]
008F17D5  push        ecx
008F17D6  call        __byteswap_uint64 (08F1348h)
008F17DB  add         esp,8
008F17DE  cdq
008F17DF  mov         dword ptr [i],eax
008F17E2  mov         dword ptr [ebp+10h],edx
with #include <stdlib.h>
i = (__int64)_byteswap_uint64((unsigned __int64)i);

001217CE  mov         eax,dword ptr [ebp+10h]
001217D1  push        eax
001217D2  mov         ecx,dword ptr [i]
001217D5  push        ecx
001217D6  call        __byteswap_uint64 (0121348h)
001217DB  add         esp,8
001217DE  mov         dword ptr [i],eax
001217E1  mov         dword ptr [ebp+10h],edx


Best Regards,
Alexander Ananin
Confidentiality Notice: This message (including attachments) is a private 
communication solely for use of the intended recipient(s). If you are not the 
intended recipient(s) or believe you received this message in error, notify the 
sender immediately and then delete this message. Any other use, retention, 
dissemination or copying is prohibited and may be a violation of law, including 
the Electronic Communication Privacy Act of 1986.   
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to