Skip to content

Commit

Permalink
#14 Using literal instead of numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
Howard Soh committed May 10, 2022
1 parent ffa56ba commit 6d448da
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 14 deletions.
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
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
7 changes: 4 additions & 3 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,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());
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

0 comments on commit 6d448da

Please sign in to comment.