Skip to content

Commit

Permalink
Handle BDB keys of different length
Browse files Browse the repository at this point in the history
  • Loading branch information
engboris committed Jul 9, 2024
1 parent 21b5d51 commit 999b859
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
5 changes: 5 additions & 0 deletions libcob/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@

2024-07-09 Boris Eng <[email protected]>

* fileio.c (bdb_bt_compare): handle BDB keys of different length with a flag
USE_BDB_KEYDIFF (passed with CPPFLAGS).

2024-05-15 Simon Sobisch <[email protected]>

* profiling.c: fix compile warnings
Expand Down
2 changes: 1 addition & 1 deletion libcob/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1977,7 +1977,7 @@ cob_cmp_all (cob_field *f1, cob_field *f2)

/* compare content of field 'f1' to content of 'f2', space padded,
using the optional collating sequence of the program */
static int
int
cob_cmp_alnum (cob_field *f1, cob_field *f2)
{
const unsigned char *col = COB_MODULE_PTR->collating_sequence;
Expand Down
1 change: 1 addition & 0 deletions libcob/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -1932,6 +1932,7 @@ COB_EXPIMP int cob_bcd_cmp (cob_field *, cob_field *);
COB_EXPIMP int cob_numeric_display_cmp (cob_field *, cob_field *);
COB_EXPIMP int cob_numeric_display_cmp_zero (cob_field *);
COB_EXPIMP int cob_bcd_cmp_zero (cob_field *);
COB_EXPIMP int cob_cmp_alnum (cob_field *, cob_field *);

/*******************************/
/* Functions in strings.c */
Expand Down
14 changes: 14 additions & 0 deletions libcob/fileio.c
Original file line number Diff line number Diff line change
Expand Up @@ -919,20 +919,34 @@ bdb_bt_compare (DB *db, const DBT *k1, const DBT *k2
)
{
const unsigned char *col = (unsigned char *)DBT_GET_APP_DATA (k1);
#ifdef USE_BDB_KEYDIFF /* flag passed with CPPFLAGS */
COB_MODULE_PTR->collating_sequence = col;
unsigned char *data1 = k1->data;
unsigned char *data2 = k2->data;
size_t size1 = (size_t)k1->size;
size_t size2 = (size_t)k2->size;
const cob_field_attr alphanum = {0x21, 0, 0, 0x0000, NULL};
cob_field f1 = {size1, data1, &alphanum};
cob_field f2 = {size2, data2, &alphanum};
return cob_cmp_alnum (&f1, &f2);
#else
COB_UNUSED (db);

/* LCOV_EXCL_START */
if (col == NULL) {
cob_runtime_error ("bdb_bt_compare was set but no collating sequence was stored in DBT");
cob_hard_failure ();
}
if (k1->size != k2->size) {
cob_runtime_error ("bdb_bt_compare was given keys of different length");
cob_hard_failure ();
}
/* LCOV_EXCL_STOP */
#if DB_VERSION_MAJOR >= 6
locp = NULL; /* docs: must be set to NULL or corruption can occur ... */
#endif
return indexed_key_compare (k1->data, k2->data, k2->size, col);
#endif
}

#endif /* WITH_DB */
Expand Down

0 comments on commit 999b859

Please sign in to comment.