Skip to content

Commit

Permalink
Correctly build RLE-encoded value arrays from Binary objects. (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
bbassett-tibco committed Feb 28, 2023
1 parent 8d1dcdb commit 6f5cdaf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ int sbdf_init_array_int(sbdf_valuetype type, int count, void const* data, int co
int calculate_lengths = lengths == 0;

is_string = type.id == SBDF_STRINGTYPEID;
if (calculate_lengths && type.id == SBDF_BINARYTYPEID)
if (clone_array && calculate_lengths && type.id == SBDF_BINARYTYPEID)
{
sbdf_obj_destroy(t);
return SBDF_ERROR_ARGUMENT_NULL;
Expand Down
3 changes: 1 addition & 2 deletions src/valuearray.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,10 @@ int sbdf_va_create_rle(sbdf_object const* array, sbdf_valuearray** handle)
return SBDF_ERROR_OUT_OF_MEMORY;
}
*(void**)out = copy;
memcpy(copy, prev_data, cur_sz);
}
else
{
memcpy(out, prev_data, cur_sz);
memcpy(out, prev_data, prev_sz);
}
++out_size;
out += elem_size;
Expand Down
18 changes: 18 additions & 0 deletions tests/valuearray_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "valuearray.h"
#include "valuearray_io.h"
#include "errors.h"

using namespace sbdf;

Expand Down Expand Up @@ -39,6 +40,23 @@ SBDF_TEST(valuearray, rle)
}
}

SBDF_TEST(valuearray, rle_binary)
{
// Test case for GH issue #3
char *data[] = {"abcd", "efgh", "ijkl", "mnop", "1234", "5678", "90-=", "\x01\x02\x03\x04" };
int data_lens[] = {4, 4, 4, 4, 4, 4, 4, 4 };

{
sbdf_object *o;
sbdf_valuearray *va;

sbdf_obj_create_arr(sbdf_vt_binary(), 8, data, data_lens, &o);
SBDF_CHECK(sbdf_va_create_rle(o, &va), SBDF_OK);
sbdf_va_destroy(va);
sbdf_obj_destroy(o);
}
}

SBDF_TEST(valuearray, bit)
{
bool a1[] = { false, false, true, false, false, true, true, false };
Expand Down

0 comments on commit 6f5cdaf

Please sign in to comment.