Skip to content

Commit

Permalink
Merge pull request #2156 from dtcenter/bugfix_14_main_v10.1_fixed_len…
Browse files Browse the repository at this point in the history
…gth_array

Bugfix dtcenter/METplus-Internal#14 main_v10.1 fixed length array
  • Loading branch information
hsoh-u authored May 10, 2022
2 parents cc7b0a8 + 44cd88d commit ee4deb7
Show file tree
Hide file tree
Showing 16 changed files with 91 additions and 61 deletions.
12 changes: 9 additions & 3 deletions met/src/basic/vx_log/concat_string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,10 @@ void ConcatString::assign(const ConcatString & c)
if (c.text()) s->assign(c.text());
else s->clear();

memcpy(FloatFormat, c.FloatFormat, sizeof(FloatFormat));
int buf_size = sizeof(c.FloatFormat);
if (buf_size > concat_string_buf_size) buf_size = concat_string_buf_size;

memcpy(FloatFormat, c.FloatFormat, buf_size);
Precision = c.Precision;
}

Expand Down Expand Up @@ -337,9 +340,12 @@ if ( (k < 0) || (k > concat_string_max_precision) ) {
if (Precision != k) {
Precision = k;

memset(FloatFormat, 0, sizeof(FloatFormat));
int buf_size = sizeof(FloatFormat);
if (buf_size > concat_string_buf_size) buf_size = concat_string_buf_size;

memset(FloatFormat, 0, buf_size);

snprintf(FloatFormat, sizeof(FloatFormat), "%%.%df", Precision);
snprintf(FloatFormat, buf_size, "%%.%df", Precision);
}

return;
Expand Down
3 changes: 2 additions & 1 deletion met/src/basic/vx_log/concat_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ static const int max_str_len = 512;
static const int concat_string_default_precision = 5;

static const int concat_string_max_precision = 12;
static const int concat_string_buf_size = concat_string_max_precision + 4;


////////////////////////////////////////////////////////////////////////
Expand All @@ -73,7 +74,7 @@ class ConcatString {

int Precision;

char FloatFormat[16];
char FloatFormat[concat_string_buf_size];

std::string *s;

Expand Down
20 changes: 14 additions & 6 deletions met/src/basic/vx_util/ascii_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,12 @@ BadDataValue = a.BadDataValue;

set_bad_data_str(a.BadDataStr);

memcpy(f_FloatFormat, a.f_FloatFormat, sizeof(f_FloatFormat));
memcpy(g_FloatFormat, a.g_FloatFormat, sizeof(g_FloatFormat));
int f_buf_size = sizeof(a.f_FloatFormat);
int g_buf_size = sizeof(a.g_FloatFormat);
if (f_buf_size > ascii_table_buf_size) f_buf_size = ascii_table_buf_size;
if (g_buf_size > ascii_table_buf_size) g_buf_size = ascii_table_buf_size;
memcpy(f_FloatFormat, a.f_FloatFormat, f_buf_size);
memcpy(g_FloatFormat, a.g_FloatFormat, g_buf_size);

DoCommaString = a.DoCommaString;

Expand Down Expand Up @@ -697,11 +701,15 @@ if ( (k < 0) || (k > ascii_table_max_precision) ) {

Precision = k;

memset(f_FloatFormat, 0, sizeof(f_FloatFormat));
memset(g_FloatFormat, 0, sizeof(g_FloatFormat));
int f_buf_size = sizeof(f_FloatFormat);
int g_buf_size = sizeof(g_FloatFormat);
if (f_buf_size > ascii_table_buf_size) f_buf_size = ascii_table_buf_size;
if (g_buf_size > ascii_table_buf_size) g_buf_size = ascii_table_buf_size;
memset(f_FloatFormat, 0, f_buf_size);
memset(g_FloatFormat, 0, g_buf_size);

snprintf(f_FloatFormat, sizeof(f_FloatFormat), "%%.%df", Precision);
snprintf(g_FloatFormat, sizeof(g_FloatFormat), "%%.%dg", Precision);
snprintf(f_FloatFormat, f_buf_size, "%%.%df", Precision);
snprintf(g_FloatFormat, g_buf_size, "%%.%dg", Precision);

return;

Expand Down
5 changes: 3 additions & 2 deletions met/src/basic/vx_util/ascii_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ static const bool default_fill_blank = false;
static const int ascii_table_default_precision = 2;

static const int ascii_table_max_precision = 12;
static const int ascii_table_buf_size = ascii_table_max_precision + 4;

static const double ascii_table_default_bad_data_value = -9999.0;

Expand Down Expand Up @@ -163,8 +164,8 @@ class AsciiTable {

std::string BadDataStr;

char f_FloatFormat[16];
char g_FloatFormat[16];
char f_FloatFormat[ascii_table_buf_size];
char g_FloatFormat[ascii_table_buf_size];


bool DoCommaString; // do comma string?
Expand Down
5 changes: 3 additions & 2 deletions met/src/basic/vx_util/observation.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <time.h>

#include "config.h"
#include "util_constants.h"

#ifdef ENABLE_PYTHON
#include "vx_python3_utils.h"
Expand Down Expand Up @@ -223,7 +224,7 @@ class Observation
{
struct tm *time_struct = gmtime(&unix_time);

char time_string[80];
char time_string[tmp_buf_size];

snprintf(time_string, sizeof(time_string),
"%04d%02d%02d_%02d%02d%02d",
Expand All @@ -240,7 +241,7 @@ class Observation
string start_time_string = _getTimeString(start_time);
string end_time_string = _getTimeString(end_time);

char time_string[80];
char time_string[tmp_buf_size];

snprintf(time_string, sizeof(time_string),
"%s-%s",
Expand Down
1 change: 1 addition & 0 deletions met/src/basic/vx_util/util_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ static const int boot_perc_flag = 1;
////////////////////////////////////////////////////////////////////////

static const int max_line_len = 2048;
static const int tmp_buf_size = 512;
static const double grib_earth_radius_km = 6371.20;
static const int default_nc_compression = 0;
static const int default_precision = 5;
Expand Down
14 changes: 7 additions & 7 deletions met/src/libcode/vx_afm/afm_keywords.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,13 @@ struct AfmKeywordInfo {
////////////////////////////////////////////////////////////////////////


static const AfmKeywordInfo kw_info[42] = {
static const int n_kw_infos = 42;


////////////////////////////////////////////////////////////////////////


static const AfmKeywordInfo kw_info[n_kw_infos] = {

{ "StartFontMetrics", afm_keyword_StartFontMetrics },
{ "EndFontMetrics", afm_keyword_EndFontMetrics },
Expand Down Expand Up @@ -134,12 +140,6 @@ static const AfmKeywordInfo kw_info[42] = {
////////////////////////////////////////////////////////////////////////


static const int n_kw_infos = 42;


////////////////////////////////////////////////////////////////////////


extern int is_afm_keyword (ConcatString text, AfmKeyword &);


Expand Down
3 changes: 2 additions & 1 deletion met/src/libcode/vx_color/color.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ extern ostream & operator<<(ostream &, const CtableEntry &);


static const int ctable_alloc_inc = 30;
static const int fudge_size = 256;


////////////////////////////////////////////////////////////////////////
Expand All @@ -226,7 +227,7 @@ class ColorTable {

double Gamma;

unsigned char fudge[256];
unsigned char fudge[fudge_size];


public:
Expand Down
6 changes: 3 additions & 3 deletions met/src/libcode/vx_color/color_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ Nalloc = 0;

int j;

for (j=0; j<256; ++j) {
for (j=0; j<fudge_size; ++j) {

fudge[j] = (unsigned char) j;

Expand Down Expand Up @@ -368,7 +368,7 @@ for (j=0; j<Nentries; ++j) {

}

for (j=0; j<256; ++j) {
for (j=0; j<fudge_size; ++j) {

fudge[j] = c.fudge[j];

Expand Down Expand Up @@ -689,7 +689,7 @@ const double exponent = 1.0/Gamma;
int j, k;
double x, y;

for (j=0; j<256; ++j) {
for (j=0; j<fudge_size; ++j) {

x = ((double) j)/255.0;

Expand Down
4 changes: 2 additions & 2 deletions met/src/libcode/vx_pxm/ppm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ if ( fabs(g - 1.0) < 1.0e-3 ) return;

int j, k;
int nxy;
unsigned char fudge[256];
unsigned char fudge[fudge_size];
double t;
double exponent;
Color color;
Expand All @@ -761,7 +761,7 @@ Color color;
exponent = 1.0/g;


for (j=0; j<256; ++j) {
for (j=0; j<fudge_size; ++j) {

t = ((double) j)/255.0;

Expand Down
4 changes: 3 additions & 1 deletion met/src/libcode/vx_render/ps_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ if ( (k < 0) || (k > max_decimal_places) ) {

DecimalPlaces = k;

snprintf(double_format, sizeof(double_format), "%%.%df", DecimalPlaces); // example: "%.5f"
int buf_size = sizeof(double_format);
if (buf_size > filter_buf_size) buf_size = filter_buf_size;
snprintf(double_format, buf_size, "%%.%df", DecimalPlaces); // example: "%.5f"


return;
Expand Down
3 changes: 2 additions & 1 deletion met/src/libcode/vx_render/ps_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ static const int FlateEncode = 4;


static const int max_filters = 10;
static const int filter_buf_size = 32;


////////////////////////////////////////////////////////////////////////
Expand All @@ -60,7 +61,7 @@ class PSFilter {

int DecimalPlaces;

char double_format[32];
char double_format[filter_buf_size];

virtual void eat(unsigned char);

Expand Down
11 changes: 6 additions & 5 deletions met/src/libcode/vx_summary/summary_obs.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "observation.h"
#include "summary_calc.h"
#include "time_summary_interval.h"
#include "util_constants.h"

////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -135,7 +136,7 @@ class SummaryObs

// Create the string

char string_buffer[20];
char string_buffer[tmp_buf_size];

snprintf(string_buffer, sizeof(string_buffer), "%02d%02d%02d", hour, minute, second);

Expand Down Expand Up @@ -222,7 +223,7 @@ class SummaryObs
{
struct tm *time_struct = gmtime(&unix_time);

char time_string[80];
char time_string[tmp_buf_size];

snprintf(time_string, sizeof(time_string),
"%04d%02d%02d_%02d%02d%02d",
Expand All @@ -239,11 +240,11 @@ class SummaryObs
memset(&time_struct, 0, sizeof(time_struct));

time_struct.tm_year = atoi(time_string.substr(0, 4).c_str()) - 1900;
time_struct.tm_mon = atoi(time_string.substr(4, 2).c_str()) - 1;
time_struct.tm_mon = atoi(time_string.substr(4, 2).c_str()) - 1;
time_struct.tm_mday = atoi(time_string.substr(6, 2).c_str());
time_struct.tm_hour = atoi(time_string.substr(9, 2).c_str());
time_struct.tm_min = atoi(time_string.substr(11, 2).c_str());
time_struct.tm_sec = atoi(time_string.substr(13, 2).c_str());
time_struct.tm_min = atoi(time_string.substr(11, 2).c_str());
time_struct.tm_sec = atoi(time_string.substr(13, 2).c_str());

return timegm(&time_struct);
}
Expand Down
2 changes: 1 addition & 1 deletion met/src/libcode/vx_time_series/compute_swinging_door.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class SDObservation
{
struct tm *time_struct = gmtime(&unix_time);

char time_string[80];
char time_string[tmp_buf_size];

snprintf(time_string, sizeof(time_string),
"%04d%02d%02d_%02d%02d%02d",
Expand Down
46 changes: 23 additions & 23 deletions met/src/tools/other/gsi_tools/rad_record.cc
Original file line number Diff line number Diff line change
Expand Up @@ -404,23 +404,23 @@ if ( n_read < 72 ) {
unsigned char * b = buf;


my_memcpy( &(R_params.isis), b, 20);
my_memcpy( &(R_params.dplat), b, 10);
my_memcpy( &(R_params.obstype), b, 10);
my_memcpy( &(R_params.isis), b, rad_isis_len);
my_memcpy( &(R_params.dplat), b, rad_dplat_len);
my_memcpy( &(R_params.obstype), b, rad_obstype_len);

my_memcpy( &(R_params.jiter), b, 4);
my_memcpy( &(R_params.nchanl), b, 4);
my_memcpy( &(R_params.npred), b, 4);
my_memcpy( &(R_params.idate), b, 4);
my_memcpy( &(R_params.ireal), b, 4);
my_memcpy( &(R_params.ipchan), b, 4);
my_memcpy( &(R_params.iextra), b, 4);
my_memcpy( &(R_params.jextra), b, 4);
my_memcpy( &(R_params.jiter), b, rad_int_len);
my_memcpy( &(R_params.nchanl), b, rad_int_len);
my_memcpy( &(R_params.npred), b, rad_int_len);
my_memcpy( &(R_params.idate), b, rad_int_len);
my_memcpy( &(R_params.ireal), b, rad_int_len);
my_memcpy( &(R_params.ipchan), b, rad_int_len);
my_memcpy( &(R_params.iextra), b, rad_int_len);
my_memcpy( &(R_params.jextra), b, rad_int_len);

my_memcpy( &(R_params.idiag), b, 4);
my_memcpy( &(R_params.angord), b, 4);
my_memcpy( &(R_params.iversion), b, 4);
my_memcpy( &(R_params.inewpc), b, 4);
my_memcpy( &(R_params.idiag), b, rad_int_len);
my_memcpy( &(R_params.angord), b, rad_int_len);
my_memcpy( &(R_params.iversion), b, rad_int_len);
my_memcpy( &(R_params.inewpc), b, rad_int_len);


if ( SwapEndian ) {
Expand Down Expand Up @@ -483,14 +483,14 @@ if ( n_read != 32 ) {

unsigned char * b = buf;

my_memcpy( &(cp.freq), b, 4);
my_memcpy( &(cp.plo), b, 4);
my_memcpy( &(cp.wave), b, 4);
my_memcpy( &(cp.varch), b, 4);
my_memcpy( &(cp.tlap), b, 4);
my_memcpy( &(cp.iuse), b, 4);
my_memcpy( &(cp.nuchan), b, 4);
my_memcpy( &(cp.ich), b, 4);
my_memcpy( &(cp.freq), b, rad_int_len);
my_memcpy( &(cp.plo), b, rad_int_len);
my_memcpy( &(cp.wave), b, rad_int_len);
my_memcpy( &(cp.varch), b, rad_int_len);
my_memcpy( &(cp.tlap), b, rad_int_len);
my_memcpy( &(cp.iuse), b, rad_int_len);
my_memcpy( &(cp.nuchan), b, rad_int_len);
my_memcpy( &(cp.ich), b, rad_int_len);

if ( SwapEndian ) {

Expand Down
13 changes: 10 additions & 3 deletions met/src/tools/other/gsi_tools/rad_record.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,21 @@
#include "vx_cal.h"


////////////////////////////////////////////////////////////////////////

static const int rad_obstype_len = 10;
static const int rad_dplat_len = 10;
static const int rad_isis_len = 20;
static const int rad_int_len = 4;

////////////////////////////////////////////////////////////////////////


struct RadParams {

char obstype [11];
char dplat [11];
char isis [21];
char obstype [rad_obstype_len+1];
char dplat [rad_dplat_len + 1];
char isis [rad_isis_len + 1];

int jiter;
int nchanl;
Expand Down

0 comments on commit ee4deb7

Please sign in to comment.