From 6d448daaceafa0a3f7fcdbb575f9463e97d8e6c4 Mon Sep 17 00:00:00 2001 From: Howard Soh Date: Mon, 9 May 2022 22:08:52 -0600 Subject: [PATCH] #14 Using literal instead of numbers --- met/src/basic/vx_util/observation.h | 5 +++-- met/src/libcode/vx_color/color.h | 3 ++- met/src/libcode/vx_color/color_table.cc | 6 +++--- met/src/libcode/vx_pxm/ppm.cc | 4 ++-- met/src/libcode/vx_render/ps_filter.cc | 4 +++- met/src/libcode/vx_render/ps_filter.h | 3 ++- met/src/libcode/vx_summary/summary_obs.h | 7 ++++--- met/src/libcode/vx_time_series/compute_swinging_door.h | 2 +- 8 files changed, 20 insertions(+), 14 deletions(-) diff --git a/met/src/basic/vx_util/observation.h b/met/src/basic/vx_util/observation.h index f9230e2dfe..58d9e29285 100644 --- a/met/src/basic/vx_util/observation.h +++ b/met/src/basic/vx_util/observation.h @@ -22,6 +22,7 @@ #include #include "config.h" +#include "util_constants.h" #ifdef ENABLE_PYTHON #include "vx_python3_utils.h" @@ -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", @@ -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", diff --git a/met/src/libcode/vx_color/color.h b/met/src/libcode/vx_color/color.h index 746b3610bb..986287aa6c 100644 --- a/met/src/libcode/vx_color/color.h +++ b/met/src/libcode/vx_color/color.h @@ -200,6 +200,7 @@ extern ostream & operator<<(ostream &, const CtableEntry &); static const int ctable_alloc_inc = 30; +static const int fudge_size = 256; //////////////////////////////////////////////////////////////////////// @@ -226,7 +227,7 @@ class ColorTable { double Gamma; - unsigned char fudge[256]; + unsigned char fudge[fudge_size]; public: diff --git a/met/src/libcode/vx_color/color_table.cc b/met/src/libcode/vx_color/color_table.cc index ed6f66843b..46157de13f 100644 --- a/met/src/libcode/vx_color/color_table.cc +++ b/met/src/libcode/vx_color/color_table.cc @@ -332,7 +332,7 @@ Nalloc = 0; int j; -for (j=0; j<256; ++j) { +for (j=0; j 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; diff --git a/met/src/libcode/vx_render/ps_filter.h b/met/src/libcode/vx_render/ps_filter.h index 23b3100de4..00bacc0e25 100644 --- a/met/src/libcode/vx_render/ps_filter.h +++ b/met/src/libcode/vx_render/ps_filter.h @@ -44,6 +44,7 @@ static const int FlateEncode = 4; static const int max_filters = 10; +static const int filter_buf_size = 32; //////////////////////////////////////////////////////////////////////// @@ -60,7 +61,7 @@ class PSFilter { int DecimalPlaces; - char double_format[32]; + char double_format[filter_buf_size]; virtual void eat(unsigned char); diff --git a/met/src/libcode/vx_summary/summary_obs.h b/met/src/libcode/vx_summary/summary_obs.h index 67b2aa353f..d83ef68018 100644 --- a/met/src/libcode/vx_summary/summary_obs.h +++ b/met/src/libcode/vx_summary/summary_obs.h @@ -19,6 +19,7 @@ #include "observation.h" #include "summary_calc.h" #include "time_summary_interval.h" +#include "util_constants.h" //////////////////////////////////////////////////////////////////////// @@ -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); @@ -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", @@ -239,7 +240,7 @@ 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()); diff --git a/met/src/libcode/vx_time_series/compute_swinging_door.h b/met/src/libcode/vx_time_series/compute_swinging_door.h index 9c990fe231..052ce0a789 100644 --- a/met/src/libcode/vx_time_series/compute_swinging_door.h +++ b/met/src/libcode/vx_time_series/compute_swinging_door.h @@ -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",