Re: [sqlite] SQLite version 3.6.21

2009-12-08 Thread Andreas Schwab
"D. Richard Hipp" <d...@hwaci.com> writes:

> For proof, could you please indicate where, exactly, we  are violating C
> aliasing rules?

See the patch.  You are storing a value of type void* in an object of
type Mem*.  This is a classical example of an obvious aliasing
violation.
 
> And what compiler are you using that is sensitive to these violations
> yet generates no warnings?

It's the very nature of undefined behaviour that it does not require a
warning.  Welcome to the world of C.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] SQLite version 3.6.21

2009-12-08 Thread Andreas Schwab
"D. Richard Hipp" <d...@hwaci.com> writes:

> On Dec 7, 2009, at 8:41 PM, Andreas Schwab wrote:
>
>> D. Richard Hipp writes:
>>
>>> As always, please let us know if you encounter any difficulties with
>>> this or any other SQLite release.
>>
>> It's still crashing due to undefined behaviour.
>>
>> $ ./sqlite3 :memory: 'create table test(integer)'
>> Segmentation fault
>>
>
>
> I am unable to reproduce this behavior.  The example above works fine
> here.  I also ran your command using valgrind and it reports no  problems.

That's the very nature of undefined behaviour.  You are violating the C
aliasing rules, and the compiler has all freedom to wreck havoc of your
code.  QED.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] SQLite version 3.6.21

2009-12-08 Thread Andreas Schwab
D. Richard Hipp writes:

> As always, please let us know if you encounter any difficulties with  
> this or any other SQLite release.

It's still crashing due to undefined behaviour.

$ ./sqlite3 :memory: 'create table test(integer)'
Segmentation fault

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
--- sqlite-3.6.21/src/vdbeaux.c.orig2009-12-01 17:08:35.0 +0100
+++ sqlite-3.6.21/src/vdbeaux.c 2009-12-08 02:27:22.0 +0100
@@ -1270,17 +1270,17 @@ void sqlite3VdbeIOTraceSql(Vdbe *p){
 ** request, then increment *pnByte by the amount of the request.
 */
 static void allocSpace(
-  char *pp,/* IN/OUT: Set *pp to point to allocated buffer */
+  void **pp,   /* IN/OUT: Set *pp to point to allocated buffer */
   int nByte,   /* Number of bytes to allocate */
   u8 **ppFrom, /* IN/OUT: Allocate from *ppFrom */
   u8 *pEnd,/* Pointer to 1 byte past the end of *ppFrom buffer */
   int *pnByte  /* If allocation cannot be made, increment *pnByte */
 ){
   assert( EIGHT_BYTE_ALIGNMENT(*ppFrom) );
-  if( (*(void**)pp)==0 ){
+  if( (*pp)==0 ){
 nByte = ROUND8(nByte);
 if( &(*ppFrom)[nByte] <= pEnd ){
-  *(void**)pp = (void *)*ppFrom;
+  *pp = (void *)*ppFrom;
   *ppFrom += nByte;
 }else{
   *pnByte += nByte;
@@ -1357,14 +1357,25 @@ void sqlite3VdbeMakeReady(
 assert( EIGHT_BYTE_ALIGNMENT(zCsr) );
 
 do {
+  void *pp;
   nByte = 0;
-  allocSpace((char*)>aMem, nMem*sizeof(Mem), , zEnd, );
-  allocSpace((char*)>aVar, nVar*sizeof(Mem), , zEnd, );
-  allocSpace((char*)>apArg, nArg*sizeof(Mem*), , zEnd, );
-  allocSpace((char*)>azVar, nVar*sizeof(char*), , zEnd, );
-  allocSpace((char*)>apCsr, 
+  pp = p->aMem;
+  allocSpace(, nMem*sizeof(Mem), , zEnd, );
+  p->aMem = pp;
+  pp = p->aVar;
+  allocSpace(, nVar*sizeof(Mem), , zEnd, );
+  p->aVar = pp;
+  pp = p->apArg;
+  allocSpace(, nArg*sizeof(Mem*), , zEnd, );
+  p->apArg = pp;
+  pp = p->azVar;
+  allocSpace(, nVar*sizeof(char*), , zEnd, );
+  p->azVar = pp;
+  pp = p->apCsr;
+  allocSpace(, 
  nCursor*sizeof(VdbeCursor*), , zEnd, 
   );
+  p->apCsr = pp;
   if( nByte ){
 p->pFree = sqlite3DbMallocZero(db, nByte);
   }
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] Fix aliasing violations

2009-11-28 Thread Andreas Schwab
A cast can never fix an aliasing violation.

Andreas.

--- sqlite-3.6.16/src/vdbeaux.c.~1~ 2009-06-26 20:17:20.0 +0200
+++ sqlite-3.6.16/src/vdbeaux.c 2009-11-27 19:19:02.0 +0100
@@ -1046,17 +1046,17 @@ void sqlite3VdbeIOTraceSql(Vdbe *p){
 ** request, then increment *pnByte by the amount of the request.
 */
 static void allocSpace(
-  char *pp,/* IN/OUT: Set *pp to point to allocated buffer */
+  void **pp,/* IN/OUT: Set *pp to point to allocated buffer */
   int nByte,   /* Number of bytes to allocate */
   u8 **ppFrom, /* IN/OUT: Allocate from *ppFrom */
   u8 *pEnd,/* Pointer to 1 byte past the end of *ppFrom buffer */
   int *pnByte  /* If allocation cannot be made, increment *pnByte */
 ){
   assert( EIGHT_BYTE_ALIGNMENT(*ppFrom) );
-  if( (*(void**)pp)==0 ){
+  if( (*pp)==0 ){
 nByte = ROUND8(nByte);
 if( (pEnd - *ppFrom)>=nByte ){
-  *(void**)pp = (void *)*ppFrom;
+  *pp = (void *)*ppFrom;
   *ppFrom += nByte;
 }else{
   *pnByte += nByte;
@@ -1131,15 +1131,26 @@ void sqlite3VdbeMakeReady(
 if( zEndaMem, nMem*sizeof(Mem), , zEnd, );
-  allocSpace((char*)>aVar, nVar*sizeof(Mem), , zEnd, );
-  allocSpace((char*)>apArg, nArg*sizeof(Mem*), , zEnd, );
-  allocSpace((char*)>azVar, nVar*sizeof(char*), , zEnd, );
-  allocSpace((char*)>apCsr, 
+  pp = p->aMem;
+  allocSpace(, nMem*sizeof(Mem), , zEnd, );
+  p->aMem = pp;
+  pp = p->aVar;
+  allocSpace(, nVar*sizeof(Mem), , zEnd, );
+  p->aVar = pp;
+  pp = p->apArg;
+  allocSpace(, nArg*sizeof(Mem*), , zEnd, );
+  p->apArg = pp;
+  pp = p->azVar;
+  allocSpace(, nVar*sizeof(char*), , zEnd, );
+  p->azVar = pp;
+  pp = p->apCsr;
+  allocSpace(, 
  nCursor*sizeof(VdbeCursor*), , zEnd, 
   );
+  p->apCsr = pp;
   if( nByte ){
 p->pFree = sqlite3DbMallocRaw(db, nByte);
   }

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users