Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature 1903 sonarqube #1911

Merged
merged 32 commits into from
Sep 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
2b80271
#1903 Added str_wrappers.cc & str_wrappers.h. They are moved from str…
Sep 8, 2021
003a5fc
#1903 Added enum_to_string.h. They are moved from enum_to_string.cc
Sep 8, 2021
1590718
#1903 Moved include statements to the top. Included enum_to_string.h …
Sep 8, 2021
b745aea
#1903 Moved m_strXXX to str_wrappers. Includes str_wrappers.h instead…
Sep 8, 2021
4e241fc
#1903 Changed strXXX to m_strXXX
Sep 8, 2021
b59eeaf
#1903 Chaged dst_info to const
Sep 8, 2021
7ff85de
#1903 Separated two || conditions to avoid potential side effect
Sep 8, 2021
cb10a13
#1903 Avoid the negative offset if the string length is 0
Sep 8, 2021
33c53c9
#1903 make sure the pointer is not NULL before releasing
Sep 8, 2021
cf8bea6
#1903 Replaced strXXX to m_strXXX. Separated two || conditions to avo…
Sep 8, 2021
30f71ae
#1903 Allow to truncate the string on calling m_strncpy
Sep 8, 2021
a598da8
#1903 Replaced strXXX calls to m_strXXX
Sep 8, 2021
77e5489
#1903 Avoid the negative offset if the string length is 0
Sep 8, 2021
8e14372
Separated third AND condition to avoid a possible side effect (assign…
Sep 9, 2021
a95e8a8
#1903 Renamed import (which is a keyword) to import_image)
Sep 9, 2021
9f93ed8
Initialize data at get_filtered_nc_data_2d
Sep 9, 2021
096be24
#1903 Initialize r, g, b at dhsv_to_drgb
Sep 9, 2021
ca814c9
Modified to avoid unreachable return statement
Sep 9, 2021
3163c59
#1903 Separated the second AND condition to avoid a potential side ef…
Sep 9, 2021
3885448
#1903 Removed unreachable break (after exit)
Sep 9, 2021
cb759e8
#1903 Removed a unused offset variable
Sep 9, 2021
66389e0
#1903 Initialize fcst variable
Sep 9, 2021
42c834e
Renamed module (keyword) to py_module
Sep 9, 2021
28d0f2f
Removed the second argument at m_strlen
Sep 9, 2021
d12143b
#1903 Deleted extra two empty lines
Sep 9, 2021
7a07773
#1903 Formatting (tab to spaces)
Sep 9, 2021
8b528dd
#1903 mstcpy is changed to m_strcpy2
Sep 10, 2021
7ea619c
Deleted the commented out code
Sep 10, 2021
17c068c
#1903 Calls sizeof instead of m_strlen at m_strcpy
Sep 10, 2021
8bbe01a
#1903 Calls m_strncpy instead of m_strcpy
Sep 10, 2021
447a7cd
#1903 Replaced m_strcpy to m_strncpy
Sep 10, 2021
09c5290
#1903 Do not use sizeof
Sep 14, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion met/src/basic/enum_to_string/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ enum_to_string_SOURCES = enum_parser.yy \
code.cc code.h \
scope.cc scope.h \
my_enum_scanner.cc \
enum_to_string.cc
enum_to_string.cc enum_to_string.h
enum_to_string_CPPFLAGS = -DCOPYRIGHT_DIR="\"${abs_top_srcdir}/data\"" ${MET_CPPFLAGS}
enum_to_string_LDFLAGS = ${MET_LDFLAGS}
enum_to_string_LDADD = -lvx_cal \
Expand Down
92 changes: 28 additions & 64 deletions met/src/basic/enum_to_string/code.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@
////////////////////////////////////////////////////////////////////////


static const bool do_name_len_decl = true;

static const bool echo_pound_define_after_endif = true;

static const char copyright_filename [] = "copyright_notice.txt"; // relative to MET_BASE_DIR


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


using namespace std;


Expand All @@ -33,43 +23,22 @@ using namespace std;
#include <cmath>

#include "code.h"
#include "enum_to_string.h"

#include "str_wrappers.h"
#include "vx_cal.h"


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


static const char * sep = "////////////////////////////////////////////////////////////////////////\n";


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


//
// these have external linkage
//


extern bool do_prefix;

extern const char * header_suffix;

extern bool do_angle_brackets;

extern bool do_array;

extern bool do_reverse;

extern bool do_concat_string;

extern bool verbose;
static const bool do_name_len_decl = true;

extern unixtime generation_gmt;
static const bool echo_pound_define_after_endif = true;

extern const char * header_filename;
static const char copyright_filename [] = "copyright_notice.txt"; // relative to MET_BASE_DIR

extern const char * program_name;
static const char * sep = "////////////////////////////////////////////////////////////////////////\n";


////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -111,7 +80,7 @@ char upper[256];
char pound_define[256];
char junk[256];
int len, scope_len, max_len;
char * len_name = (char *) 0;
char * len_name = (char *) NULL;


// if ( e.scope() ) snprintf(full_id, sizeof(full_id), "%s::%s", e.scope(), e.id(j));
Expand All @@ -121,12 +90,12 @@ max_len = 0;



if ( e.scope() ) scope_len = strlen(e.scope()) + 2; // includes "::"
if ( e.scope() ) scope_len = m_strlen(e.scope()) + 2; // includes "::"
else scope_len = 0;

for (j=0; j<(e.n_ids()); ++j) {

len = strlen(e.id(j));
len = m_strlen(e.id(j));

len += scope_len;

Expand Down Expand Up @@ -265,11 +234,6 @@ if ( do_array ) {

}

// f << "#endif // " << pound_define << "\n"
// << "\n\n"
// << sep
// << "\n\n";

f << "#endif";

if ( echo_pound_define_after_endif ) f << " /* " << pound_define << " */\n";
Expand All @@ -285,7 +249,7 @@ f << "\n\n"

f.close();

if ( len_name ) { delete [] len_name; len_name = (char *) 0; }
if ( len_name ) { delete [] len_name; len_name = (char *) NULL; }

return;

Expand All @@ -301,15 +265,14 @@ void write_cs_header(const EnumInfo & e)

if ( e.n_ids() == 0 ) return;

int j;
ofstream f;
char filename[256];
char lower[256];
char upper[256];
char pound_define[256];
char junk[256];
int len, scope_len, max_len;
char * len_name = (char *) 0;
char * len_name = (char *) NULL;


// if ( e.scope() ) snprintf(full_id, sizeof(full_id), "%s::%s", e.scope(), e.id(j));
Expand All @@ -319,12 +282,12 @@ max_len = 0;



if ( e.scope() ) scope_len = strlen(e.scope()) + 2; // includes "::"
if ( e.scope() ) scope_len = m_strlen(e.scope()) + 2; // includes "::"
else scope_len = 0;

for (j=0; j<(e.n_ids()); ++j) {
for (int j=0; j<(e.n_ids()); ++j) {

len = strlen(e.id(j));
len = m_strlen(e.id(j));

len += scope_len;

Expand Down Expand Up @@ -486,7 +449,7 @@ f << "\n\n"

f.close();

if ( len_name ) { delete [] len_name; len_name = (char *) 0; }
if ( len_name ) { delete [] len_name; len_name = (char *) NULL; }

return;

Expand Down Expand Up @@ -766,7 +729,7 @@ for (j=0; j<(e.n_ids()); ++j) {
if ( e.scope() ) snprintf(full_id, sizeof(full_id), "%s::%s", e.scope(), e.id(j));
else snprintf(full_id, sizeof(full_id), "%s", e.id(j));

k = strlen(e.id(j));
k = m_strlen(e.id(j));

out << " " << "case " << full_id << ": ";

Expand Down Expand Up @@ -850,7 +813,7 @@ for (j=0; j<(e.n_ids()); ++j) {
if ( e.scope() ) snprintf(full_id, sizeof(full_id), "%s::%s", e.scope(), e.id(j));
else snprintf(full_id, sizeof(full_id), "%s", e.id(j));

k = strlen(e.id(j));
k = m_strlen(e.id(j));

out << " " << "case " << full_id << ": ";

Expand Down Expand Up @@ -927,7 +890,7 @@ n = e.n_ids();

for (j=0; j<n; ++j) {

k = strlen(e.id(j));
k = m_strlen(e.id(j));

if ( j == 0 ) out << " ";
else out << "else ";
Expand Down Expand Up @@ -991,7 +954,7 @@ void make_lowercase(const char * in, char * out)

int j, k;

k = strlen(in);
k = m_strlen(in);

for (j=0; j<k; ++j) {

Expand All @@ -1016,7 +979,7 @@ void make_uppercase(const char * in, char * out)

int j, k;

k = strlen(in);
k = m_strlen(in);

for (j=0; j<k; ++j) {

Expand Down Expand Up @@ -1045,7 +1008,7 @@ unixtime t;
char junk[256];
const char * ampm = "am";
const char * zone = "MST";
const char * short_name = (const char *) 0;
const char * short_name = (const char *) NULL;



Expand Down Expand Up @@ -1080,7 +1043,7 @@ snprintf(junk, sizeof(junk), "%s %d, %d %d:%02d %s %s",
// strip the leading path from header_filename
//

j = strlen(header_filename) - 1;
j = m_strlen(header_filename) - 1;

while ( (j >= 0) && (header_filename[j] != '/') ) --j;

Expand Down Expand Up @@ -1118,10 +1081,11 @@ void patch_name(char * len_name)

int j, n;
int pos;
char * new_name = (char *) 0;
char * new_name = (char *) NULL;
char c;
const char *method_name = "patch_name() -> ";

n = strlen(len_name);
n = m_strlen(len_name);

new_name = new char [n + 1];

Expand Down Expand Up @@ -1151,14 +1115,14 @@ for (j=0; j<n; ++j) {

new_name[pos++] = (char) 0;

strcpy(len_name, new_name);
m_strcpy(len_name, new_name, method_name);


//
// done
//

if ( new_name ) { delete [] new_name; new_name = (char *) 0; }
if ( new_name ) { delete [] new_name; new_name = (char *) NULL; }

return;

Expand Down Expand Up @@ -1196,7 +1160,7 @@ for (j=0; j<=jmax; ++j) {

f << " ";

for (k=strlen(e.id(j)); k<max_len; ++k) f.put(' ');
for (k=m_strlen(e.id(j)); k<max_len; ++k) f.put(' ');

f << "// # " << j;

Expand Down
6 changes: 3 additions & 3 deletions met/src/basic/enum_to_string/enum_to_string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ using namespace std;
#include "scope.h"

#include "vx_log.h"
#include "vx_cal.h"
#include "enum_to_string.h"


////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -129,7 +129,7 @@ int main(int argc, char * argv[])

generation_gmt = time(0);

int j = strlen(argv[0]) - 1;
int j = m_strlen(argv[0]) - 1;

while ( (j >= 0) && (argv[0][j] != '/') ) --j;

Expand Down Expand Up @@ -395,7 +395,7 @@ void yyerror(const char * s)

int c;

c = (int) (column - strlen(yytext));
c = (int) (column - m_strlen(yytext));

cout << "\n\n " << program_name << " -> "
<< "syntax error in file \"" << header_filename << "\" at line " << LineNumber
Expand Down
55 changes: 55 additions & 0 deletions met/src/basic/enum_to_string/enum_to_string.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
// ** Copyright UCAR (c) 1992 - 2021
// ** University Corporation for Atmospheric Research (UCAR)
// ** National Center for Atmospheric Research (NCAR)
// ** Research Applications Lab (RAL)
// ** P.O.Box 3000, Boulder, Colorado, 80307-3000, USA
// *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*


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


#ifndef __ENUM_TO_STRING_H__
#define __ENUM_TO_STRING_H__


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


#include "vx_cal.h"


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


extern bool do_prefix;

extern const char * header_suffix;

extern bool do_angle_brackets;

extern bool do_array;

extern bool do_reverse;

extern bool do_concat_string;

extern bool verbose;

extern unixtime generation_gmt;

extern const char * header_filename;

extern const char * program_name;


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


#endif /* __ENUM_TO_STRING_H__ */


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


Loading