diff --git a/dap/DapUtils.cc b/dap/DapUtils.cc index 4544fbd5b0..44bbc70afe 100644 --- a/dap/DapUtils.cc +++ b/dap/DapUtils.cc @@ -307,7 +307,15 @@ uint64_t crsaibv_process_variable( } else { // width_ll() returns the number of bytes needed to hold the data - uint64_t vsize = var->width_ll(true); + uint64_t vsize = 0; + // If the data type is string, in C++, sizeof(string) is always 24. So the total size for a string array is + // always 24 x number of elements of this array, which may cause false positive for the server to issue + // an error that the maximum response size is exceeded. To avoid this case, we choose to use the minimal possible string size + // for a C string 2: 1 character and 1 terminator. This is also the case for a real NASA file. + if (var->type()==dods_array_c && var->var()->type() == dods_str_c) + vsize = 2*var->length_ll(); + else + vsize = var->width_ll(true); response_size += vsize; BESDEBUG(MODULE_VERBOSE, prolog << " " << get_dap_decl(var) << "(" << vsize << " bytes)" << endl); diff --git a/dap/unit-tests/DapUtilsTest.cc b/dap/unit-tests/DapUtilsTest.cc index 6cf419cf0b..4afd71fea4 100644 --- a/dap/unit-tests/DapUtilsTest.cc +++ b/dap/unit-tests/DapUtilsTest.cc @@ -417,7 +417,7 @@ class DapUtilsTest : public CppUnit::TestFixture { stringstream msg; uint64_t response_size = 0; - uint64_t expected_response_size = 1016; + uint64_t expected_response_size = 752; uint64_t max_var_size = 200; std::vector too_big; @@ -433,7 +433,7 @@ class DapUtilsTest : public CppUnit::TestFixture { for(auto entry:too_big){ DBG(cerr << prolog << " " << entry << endl); } - CPPUNIT_ASSERT( too_big.size() == 2 ); + CPPUNIT_ASSERT( too_big.size() == 1 ); } else { CPPUNIT_FAIL("ERROR: No variables were deemed too big!");