Skip to content

Commit

Permalink
BUFR: Fix membuffer copy
Browse files Browse the repository at this point in the history
  • Loading branch information
istvans-mn committed Sep 30, 2024
1 parent 5aabf54 commit 93d6cd2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
10 changes: 5 additions & 5 deletions ingest/src/ingest/bufr/NorBufr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,14 +640,14 @@ uint64_t NorBufr::fromBuffer(char *ext_buf, u_int64_t ext_buf_pos,
if (n >= ext_buf_size) {
lb.addLogEntry(
LogEntry("No more BUFR messages", LogLevel::WARN, __func__, bufr_id));
return 0;
return n;
}

// Section0 length
uint64_t slen = 8;
uint8_t sec0[slen];
if (ext_buf_pos + slen < ext_buf_size) {
memcpy(sec0, ext_buf + ext_buf_pos, slen);
if (ext_buf_pos + n + slen < ext_buf_size) {
memcpy(sec0, ext_buf + ext_buf_pos + n, slen);
}

len = NorBufrIO::getBytes(sec0 + 4, 3);
Expand All @@ -660,8 +660,8 @@ uint64_t NorBufr::fromBuffer(char *ext_buf, u_int64_t ext_buf_pos,
buffer = new uint8_t[len];
memcpy(buffer, sec0, slen);

if (ext_buf_pos + len <= ext_buf_size) {
memcpy(buffer + slen, ext_buf + ext_buf_pos + slen, len - slen);
if (ext_buf_pos + n + len <= ext_buf_size) {
memcpy(buffer + slen, ext_buf + ext_buf_pos + n + slen, len - slen);
}

int offset = checkBuffer();
Expand Down
8 changes: 5 additions & 3 deletions ingest/src/ingest/bufr/NorBufrIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ uint64_t NorBufrIO::findBytes(char *buf, unsigned int buf_size, const char *seq,
unsigned int size) {
uint64_t j = 0;
char c;
while (j < size && j < buf_size) {
c = buf[j];
uint64_t position = 0;
while (j < size && position < buf_size) {
c = buf[position];
if (c == seq[j]) {
++j;
} else {
Expand All @@ -74,8 +75,9 @@ uint64_t NorBufrIO::findBytes(char *buf, unsigned int buf_size, const char *seq,
j = 0;
}
}
++position;
}
return (j < size ? ULONG_MAX : j);
return (j < size ? ULONG_MAX : position - size);
}

uint64_t NorBufrIO::getBytes(uint8_t *buffer, int size) {
Expand Down
8 changes: 5 additions & 3 deletions ingest/src/ingest/bufr/bufresohmsg_py.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ std::list<std::string> norbufr_bufresohmsg(std::string fname) {
std::list<std::string> norbufr_bufresohmsgmem(char *api_buf, int api_size) {

std::list<std::string> ret;
int position = 0;
uint64_t position = 0;

while (position < api_size) {
while (position < static_cast<uint64_t>(api_size)) {

ESOHBufr *bufr = new ESOHBufr;
// TODO:
Expand All @@ -146,7 +146,9 @@ std::list<std::string> norbufr_bufresohmsgmem(char *api_buf, int api_size) {
bufr->setMsgTemplate(bufr_input_schema);
bufr->setShadowWigos(default_shadow_wigos_py);

int n = bufr->fromBuffer(api_buf, position, api_size);
uint64_t n = bufr->fromBuffer(api_buf, position, api_size);
if (n == ULONG_MAX)
position = ULONG_MAX;
if (n > position) {
position = n;
bufr->setTableB(
Expand Down

1 comment on commit 93d6cd2

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API Unit Test Coverage Report
FileStmtsMissCoverMissing
\_\_init\_\_.py00100% 
datastore_pb2.py614821%34–81
datastore_pb2_grpc.py542750%15–16, 19, 57–72, 105–107, 112–114, 119–121, 126–128, 132–157, 195, 222, 249, 276
export_metrics.py100100% 
grpc_getter.py201145%15–19, 23–26, 30–32, 36–38
locustfile.py15150%1–31
main.py43784%45, 50, 60, 70–71, 81–82
metadata_endpoints.py632954%45–54, 58, 85, 100–216, 220
response_classes.py50100% 
utilities.py1815669%20, 38, 45, 67–70, 78–89, 94–101, 121, 125, 127, 154, 157, 166, 184–185, 189, 205–210, 215, 219–220, 224–226, 232–240, 250–253, 259–260, 272–276, 299, 304, 317
custom_geo_json
   edr_feature_collection.py60100% 
formatters
   \_\_init\_\_.py110100% 
   covjson.py57198%88
   geojson.py17288%21, 46
openapi
   custom_dimension_examples.py40100% 
   edr_query_parameter_descriptions.py110100% 
   openapi_examples.py130100% 
routers
   \_\_init\_\_.py00100% 
   edr.py102496%350–351, 441–442
   feature.py471960%99–132, 148–153, 159–181
TOTAL72021970% 

API Unit Test Coverage Summary

Tests Skipped Failures Errors Time
30 0 💤 0 ❌ 0 🔥 1.932s ⏱️

Please sign in to comment.