Bug in sqlite3PagerSharedLock?
(1) By Hugo Lefeuvre (hlefeuvre) on 2021-07-27 12:34:59 [link] [source]
Hi,
Not entirely sure about this, but it looks to me like the following snippet (from sqlite3PagerSharedLock in pager.c [0]) has a bug:
char dbFileVers[sizeof(pPager->dbFileVers)];
IOTRACE(("CKVERS %p %d\n", pPager, sizeof(dbFileVers)));
rc = sqlite3OsRead(pPager->fd, &dbFileVers, sizeof(dbFileVers), 24);
if( rc!=SQLITE_OK ){
if( rc!=SQLITE_IOERR_SHORT_READ ){
goto failed;
}
memset(dbFileVers, 0, sizeof(dbFileVers));
}
Shouldn't it be
char dbFileVers[sizeof(pPager->dbFileVers)];
IOTRACE(("CKVERS %p %d\n", pPager, sizeof(dbFileVers)));
rc = sqlite3OsRead(pPager->fd, dbFileVers, sizeof(dbFileVers), 24);
if( rc!=SQLITE_OK ){
if( rc!=SQLITE_IOERR_SHORT_READ ){
goto failed;
}
memset(dbFileVers, 0, sizeof(dbFileVers));
}
instead? i.e., replace &dbFileVers
with dbFileVers
in the sqlite3OsRead
call.
Cheers, Hugo
[0] https://github.com/sqlite/sqlite/blob/master/src/pager.c#L5342
(2) By Richard Hipp (drh) on 2021-07-27 12:53:40 in reply to 1 [source]
Because dbFileVers
is an array, "dbFileVers
" (the variable name without a
subsequent [..]) and "&dbFileVers
" (the variable name preceded by "&
")
mean the same thing in C. So this is not a bug.
(3) By Hugo Lefeuvre (hlefeuvre) on 2021-07-27 13:01:55 in reply to 2 [link] [source]
Oh, right, thanks, my bad! I changed this snippet to use a dynamically allocated heap pointer in my local fork and so this wasn't true anymore...
Anyways, thanks for the quick answer.