Skip to content

Instantly share code, notes, and snippets.

@springmeyer
Created November 14, 2011 20:30
Show Gist options
  • Save springmeyer/1365052 to your computer and use it in GitHub Desktop.
Save springmeyer/1365052 to your computer and use it in GitHub Desktop.
sqlite3 trunk undefined behavior
Index: ext/rtree/README
===================================================================
--- ext/rtree/README
+++ ext/rtree/README
@@ -22,11 +22,11 @@
All r-tree virtual tables have an odd number of columns between
3 and 11. Unlike regular SQLite tables, r-tree tables are strongly
typed.
- The leftmost column is always the pimary key and contains 64-bit
+ The leftmost column is always the primary key and contains 64-bit
integer values. Each subsequent column contains a 32-bit real
value. For each pair of real values, the first (leftmost) must be
less than or equal to the second. R-tree tables may be
constructed using the following syntax:
@@ -104,11 +104,11 @@
gcc -shared rtree.c -o libSqliteRtree.so
You may need to add "-I" flags so that gcc can find sqlite3ext.h
and sqlite3.h. The resulting shared lib, libSqliteRtree.so, may be
- loaded into sqlite in the same way as any other dynamicly loadable
+ loaded into sqlite in the same way as any other dynamically loadable
extension.
3. REFERENCES
Index: ext/rtree/rtree.c
===================================================================
Index: tool/lemon.c
===================================================================
--- tool/lemon.c
+++ tool/lemon.c
@@ -3447,11 +3447,11 @@
stddt[j] = 0;
if( lemp->tokentype && strcmp(stddt, lemp->tokentype)==0 ){
sp->dtnum = 0;
continue;
}
- hash = 0;
+ unsigned long long hash = 0;
for(j=0; stddt[j]; j++){
hash = hash*53 + stddt[j];
}
hash = (hash & 0x7fffffff)%arraysize;
while( types[hash] ){
@@ -4234,12 +4234,16 @@
** Code for processing tables in the LEMON parser generator.
*/
PRIVATE int strhash(const char *x)
{
- int h = 0;
- while( *x) h = h*13 + *(x++);
+ unsigned long long h = 0;
+ while( *x) {
+ const char x0 = *(x++);
+ if (x0)
+ h = h*13 + x0;
+ }
return h;
}
/* Works like strdup, sort of. Save a string in malloced memory, but
** keep strings in a table so that the same string is not in more
@@ -4362,10 +4366,12 @@
/* Return a pointer to data assigned to the given key. Return NULL
** if no such key. */
const char *Strsafe_find(const char *key)
{
+ if (!key)
+ return 0;
int h;
x1node *np;
if( x1a==0 ) return 0;
h = strhash(key) & (x1a->size-1);
@@ -4606,11 +4612,11 @@
}
/* Hash a state */
PRIVATE int statehash(struct config *a)
{
- int h=0;
+ unsigned long long h=0;
while( a ){
h = h*571 + a->rp->index*37 + a->dot;
a = a->bp;
}
return h;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment