"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/dbh_static.i" between
libdbh2-5.0.21.tar.gz and libdbh2-5.0.22.tar.gz

About: GNU Libdbh is a small library to create and manage 64-bit disk based hash tables. (quite similar to GNU gdbm but with increased performance when the number of are records are very high).

dbh_static.i  (libdbh2-5.0.21):dbh_static.i  (libdbh2-5.0.22)
skipping to change at line 1022 skipping to change at line 1022
the_key = dbh->newkey; the_key = dbh->newkey;
} else { } else {
the_branches = dbh->branch; the_branches = dbh->branch;
the_data = dbh->data; the_data = dbh->data;
how_many_branches = &(dbh->branches); how_many_branches = &(dbh->branches);
the_user_databytes = &(dbh->bytes_userdata); the_user_databytes = &(dbh->bytes_userdata);
the_key = dbh->key; the_key = dbh->key;
} }
keylength = dbh->head_info->n_limit; keylength = dbh->head_info->n_limit;
#if 1 if (DBH_MAXIMUM_RECORD_SIZE(dbh) < 16 * 4096) {
/* new code: reduce read() call count from 6 to 3 */ /* new code: reduce read() call count from 3 to 1,
int buffer_size = 2+sizeof(FILE_POINTER); * but only with reasonable maximum data size (stack size is limited)
unsigned char buffer[buffer_size]; * the value 16 * 4096 is arbitrary, but sounds OK. */
if(read (dbh->fd, buffer, buffer_size) != buffer_size) { /*
DBG ("read error 2.1.1 (on empty dbh file this is OK)\n"); * Minimum bytes to read: 2+sizeof(FILE_POINTER)
return 0; * (unsigned char, unsigned char, FILE_POINTER)
} * Maximum bytes to read: 2+sizeof(FILE_POINTER) + 256 + 256 * sizeof(FI
memcpy(how_many_branches, buffer, 1); LE_POINTER)
memcpy(&(dbh->flag), buffer+1, 1); * (add 256 FILE_POINTERs and 256 unsigned chars for the key and maxim
memcpy (the_user_databytes, buffer+2, sizeof(FILE_POINTER)); um data size)
* */
int min_bytes = 2+sizeof(FILE_POINTER);
int max_bytes = min_bytes + 256 + (256 * sizeof(FILE_POINTER)) + DBH_MAX
IMUM_RECORD_SIZE(dbh);
unsigned char buffer[max_bytes];
int bytes = read (dbh->fd, buffer, max_bytes);
if (bytes < min_bytes){
DBG ("read error 2.1.1 (on empty dbh file this is OK)\n");
return 0;
}
memcpy(how_many_branches, buffer, 1);
memcpy(&(dbh->flag), buffer+1, 1);
memcpy (the_user_databytes, buffer+2, sizeof(FILE_POINTER));
#ifdef TURN #ifdef TURN
{
int i;
for(i = 0; i < *how_many_branches; i++)
*the_user_databytes = sdbh_turnaround (*the_user_databytes); *the_user_databytes = sdbh_turnaround (*the_user_databytes);
}
#endif #endif
if(*the_user_databytes > dbh->head_info->record_length) { if(*the_user_databytes > dbh->head_info->record_length) {
ERR("sdbh_read(): user databytes is greater than head_info->record_lengt ERR("sdbh_read(): user databytes is greater than head_info->record_l
h. This should not happen.\n"); ength. This should not happen.\n");
return 0; return 0;
} }
if(*the_user_databytes == 0) { if(*the_user_databytes == 0) {
ERR ( "dbh_RECORD_SIZE() == 0. If this is not intentional, use dbh_set_r DBG ( "dbh_RECORD_SIZE() == 0. If this is not intentional, use dbh_s
ecordsize() to set record size for %s.\n", dbh->path); et_recordsize() to set record size for %s.\n",
return 0; dbh->path);
} return 0;
}
int structure_buffer_size = (sizeof (FILE_POINTER) * (*how_many_branches)) + int structure_buffer_size = (sizeof (FILE_POINTER) * (*how_many_branches
keylength; )) + keylength;
unsigned char structure_buffer[structure_buffer_size]; int correct_bytes = min_bytes + structure_buffer_size + *the_user_databy
if(read (dbh->fd, structure_buffer, structure_buffer_size) != structure_buff tes;
er_size) { if(bytes < correct_bytes) {
ERR ("fread error 2.4\n"); ERR ("fread error 2.4\n");
return 0; return 0;
} }
memcpy(the_branches, structure_buffer, structure_buffer_size - keylength); void *structure_buffer = buffer + min_bytes;
memcpy(the_key, structure_buffer + (structure_buffer_size - keylength), keyl memcpy(the_branches, structure_buffer, structure_buffer_size - keylength
ength); );
memcpy(the_key, structure_buffer + (structure_buffer_size - keylength),
keylength);
#ifdef TURN #ifdef TURN
{ {
int i; int i; for(i = 0; i < *how_many_branches; i++)
for(i = 0; i < *how_many_branches; i++) the_branches[i] = sdbh_turnaround (the_branches[i]);
the_branches[i] = sdbh_turnaround (the_branches[i]); }
}
#endif #endif
if(read_data) {
#else memcpy(the_data, structure_buffer + structure_buffer_size, *the_user
/* deprecated code */ _databytes);
if(read (dbh->fd, how_many_branches, 1) != 1) { }
DBG ("fread error 2.1 (on empty dbh file this is OK)\n"); } else {
return 0; int buffer_size = 2+sizeof(FILE_POINTER);
} unsigned char buffer[buffer_size];
if(read (dbh->fd, &(dbh->flag), 1) != 1) { if(read (dbh->fd, buffer, buffer_size) != buffer_size) {
DBG ("read error 2.1.1 (on empty dbh file this is OK)\n");
ERR ("fread error 2.2\n"); return 0;
return 0; }
} memcpy(how_many_branches, buffer, 1);
// the_user_databytes is *not* a string. It is a FILE_POINTER (gint64) memcpy(&(dbh->flag), buffer+1, 1);
// coverity[string_null_argument : FALSE] memcpy (the_user_databytes, buffer+2, sizeof(FILE_POINTER));
if(read (dbh->fd, the_user_databytes, sizeof (FILE_POINTER)) != sizeof (FILE
_POINTER)) {
ERR ("fread error 2.3\n");
return 0;
}
if(*the_user_databytes > dbh->head_info->record_length) {
ERR("sdbh_read(): user databytes is greater than head_info->record_lengt
h. This should not happen.\n");
return 0;
}
if(*the_user_databytes == 0) {
ERR ( "dbh_RECORD_SIZE() == 0. If this is not intentional, use dbh_set_r
ecordsize() to set record size for %s.\n", dbh->path);
return 0;
}
// if data is tainted, there will be no overrun since value is checked again
st
// dbh->head_info->record_length above.
// coverity[tainted_data : FALSE]
if(read (dbh->fd, the_branches, sizeof (FILE_POINTER) * (*how_many_branches)
) != sizeof (FILE_POINTER) * (*how_many_branches)) {
ERR ("fread error 2.4\n");
return 0;
}
#ifdef TURN #ifdef TURN
{ *the_user_databytes = sdbh_turnaround (*the_user_databytes);
int i;
for(i = 0; i < *how_many_branches; i++)
the_branches[i] = sdbh_turnaround (the_branches[i]);
}
#endif
if(read (dbh->fd, the_key, keylength) != keylength) {
ERR ("fread error 2.5\n");
return 0;
}
#endif #endif
// This may be a very big read, better left by itself. if(*the_user_databytes > dbh->head_info->record_length) {
if(read_data) { ERR("sdbh_read(): user databytes is greater than head_info->record_l
// if data is tainted, there will be no overrun since value is checked a ength. This should not happen.\n");
gainst return 0;
// dbh->head_info->record_length above. }
// coverity[tainted_data : FALSE] if(*the_user_databytes == 0) {
if(read (dbh->fd, the_data, *the_user_databytes) != *the_user_databytes) ERR ( "dbh_RECORD_SIZE() == 0. If this is not intentional, use dbh_s
{ et_recordsize() to set record size for %s.\n", dbh->path);
ERR ("fread error 2.51: blocksize=%lld\n", (long long)(*the_user_dat return 0;
abytes)); }
int structure_buffer_size = (sizeof (FILE_POINTER) * (*how_many_branches
)) + keylength;
unsigned char structure_buffer[structure_buffer_size];
if(read (dbh->fd, structure_buffer, structure_buffer_size) != structure_
buffer_size) {
ERR ("fread error 2.4\n");
return 0; return 0;
} }
memcpy(the_branches, structure_buffer, structure_buffer_size - keylength
);
memcpy(the_key, structure_buffer + (structure_buffer_size - keylength),
keylength);
#ifdef TURN
{
int i; for(i = 0; i < *how_many_branches; i++)
the_branches[i] = sdbh_turnaround (the_branches[i]);
}
#endif
// This may be a very big read, better left by itself.
if(read_data) {
// if data is tainted, there will be no overrun since value is check
ed against
// dbh->head_info->record_length above.
// coverity[tainted_data : FALSE]
if(read (dbh->fd, the_data, *the_user_databytes) != *the_user_databy
tes) {
ERR ("fread error 2.51: blocksize=%lld\n", (long long)(*the_user
_databytes));
return 0;
}
}
} }
//
return 1; return 1;
} /***************************************************************************** *******/ } /***************************************************************************** *******/
static int static int
sdbh_readheader (DBHashTable * dbh) { sdbh_readheader (DBHashTable * dbh) {
TRACE ("sdbh_readheader\n"); TRACE ("sdbh_readheader\n");
if(!place_fp_at (dbh, (off_t)0)) { if(!place_fp_at (dbh, (off_t)0)) {
ERR("*** sdbh_readheader() error 1; !place_fp_at (dbh, 0)\n"); ERR("*** sdbh_readheader() error 1; !place_fp_at (dbh, 0)\n");
return 0; return 0;
} }
 End of changes. 11 change blocks. 
105 lines changed or deleted 108 lines changed or added

Home  |  About  |  All  |  Newest  |  Fossies Dox  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTPS