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 1855 sonarqube fix strlen & strcpy #1898

Merged
merged 24 commits into from
Aug 31, 2021
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d7ca364
#1855 Initialize AllocInc
Aug 31, 2021
0d322f2
855 call snprintf instead of sprintf
Aug 31, 2021
c099f60
Avoid the same for loops (SobarQube warns this)
Aug 31, 2021
868ab7d
#1855 Checking the minimum rows (3) for formatting. Initialize left &…
Aug 31, 2021
30ce2e5
#1855 Removed the unreachable return statement
Aug 31, 2021
eafb807
#1855 Avoide out of index for v_miss
Aug 31, 2021
ae6a6c2
#1855 Keep buf_size for for-loop (avoid changing it in for loop). The…
Aug 31, 2021
e94048b
#1855 Make sure the variuble c has enough data to avoid out of index …
Aug 31, 2021
fb843da
#1855 nake sure the index is in range (avoid out of index error)
Aug 31, 2021
56ec1bf
#1855 Make sure no negative offset for s array
Aug 31, 2021
ee6e4c6
#1855 Allocated line before calling getline'. Simplify the code to ch…
Aug 31, 2021
955a8ca
#1855 Added m_strlen, m_strcpy, m_strcpy2, and m_strncpy
Aug 31, 2021
116c4e2
#1855 Added m_strlen, m_strcpy, m_strcpy2, and m_strncpy> Check if nu…
Aug 31, 2021
489923f
#1855 Calls m_strcpy intead of strcpy
Aug 31, 2021
8b0a8cf
#1855 Calls m_strcpy2 intead of strcpy
Aug 31, 2021
f691aa5
#1855 Calls m_strcpy intead of strcpy
Aug 31, 2021
3de9c3d
Merge branch 'develop' of github.com:dtcenter/MET into feature_1855_s…
Aug 31, 2021
7fb2ecd
#1855 Removed spaces at the empty line
Aug 31, 2021
d80307c
#1855 sonarqube: replaced strlen to m_strlen
Aug 31, 2021
183f53f
#1855 sonarqube: replaced strcpy to m_strcpy
Aug 31, 2021
7b1a64b
#1855 sonarqube: replaced strlen to m_strlen
Aug 31, 2021
cf8ef98
#1855 sonarqube: replaced strlen to m_strlen
Aug 31, 2021
5acda75
#1855 sonarqube: replaced strlen to m_strlen
Aug 31, 2021
4b975a6
Merge branch 'develop' into feature_1855_sobarqube_fix
JohnHalleyGotway Aug 31, 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
4 changes: 2 additions & 2 deletions met/src/basic/enum_to_string/my_enum_scanner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ int do_id()

{

// column += strlen(yytext);
// column += m_strlen(yytext);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// column += m_strlen(yytext);

Instead of editing commented out code, let's just remove it.


if ( enum_mode || last_was_enum || last_was_class ) {

Expand All @@ -456,7 +456,7 @@ int do_int()

{

// column += strlen(yytext);
// column += m_strlen(yytext);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// column += m_strlen(yytext);

Instead of editing commented out code, let's just remove it.


if ( !enum_mode ) return ( 0 );

Expand Down
4 changes: 3 additions & 1 deletion met/src/basic/vx_config/config_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ using namespace std;

#include "vx_math.h"
#include "vx_util.h"
#include "string_fxns.h"

#include "GridTemplate.h"

Expand Down Expand Up @@ -2343,8 +2344,9 @@ const char * statlinetype_to_string(const STATLineType t) {
///////////////////////////////////////////////////////////////////////////////

void statlinetype_to_string(const STATLineType t, char *out) {
const char *method_name = "statlinetype_to_string() -> ";

strcpy(out, statlinetype_to_string(t));
m_strcpy(out, statlinetype_to_string(t), method_name);

return;
}
Expand Down
23 changes: 15 additions & 8 deletions met/src/basic/vx_config/icode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ using namespace std;
#include "indent.h"
#include "icode.h"
#include "dictionary.h"
#include "string_fxns.h"

#include "celltype_to_string.h"

Expand Down Expand Up @@ -162,6 +163,8 @@ void IcodeCell::assign(const IcodeCell & icc)

{

const char *method_name = "IcodeCell::assign() -> ";

i = icc.i;

d = icc.d;
Expand All @@ -170,17 +173,17 @@ type = icc.type;

if ( type == identifier ) {

name = new char [1 + strlen(icc.name)];
name = new char [1 + m_strlen(icc.name)];

strcpy(name, icc.name);
m_strcpy(name, icc.name, method_name, "name");

}

if ( type == character_string ) {

text = new char [1 + strlen(icc.text)];
text = new char [1 + m_strlen(icc.text)];

strcpy(text, icc.text);
m_strcpy(text, icc.text, method_name, "text");

}

Expand Down Expand Up @@ -413,13 +416,15 @@ void IcodeCell::set_identifier(const char * Text)

{

const char *method_name = "IcodeCell::set_identifier() -> ";

clear();

type = identifier;

name = new char [1 + strlen(Text)];
name = new char [1 + m_strlen(Text)];

strcpy(name, Text);
m_strcpy(name, Text, method_name);


return;
Expand All @@ -434,15 +439,17 @@ void IcodeCell::set_string(const char * Text)

{

const char *method_name = "IcodeCell::set_string() -> ";

clear();

const int n = strlen(Text);
const int n = m_strlen(Text);

type = character_string;

text = new char [1 + n];

strcpy(text, Text);
m_strcpy(text, Text, method_name);

text[n] = 0;

Expand Down
9 changes: 5 additions & 4 deletions met/src/basic/vx_config/my_config_scanner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ using namespace std;
#include "math_constants.h"
#include "util_constants.h"
#include "is_number.h"
#include "string_fxns.h"

#include "dictionary.h"
#include "builtin.h"
Expand Down Expand Up @@ -527,7 +528,7 @@ int do_id()

int j, k;

Column += strlen(configtext);
Column += m_strlen(configtext);

if ( is_lhs ) { strncpy(configlval.text, configtext, max_id_length); return ( IDENTIFIER ); }

Expand Down Expand Up @@ -657,7 +658,7 @@ int do_int()

{

// Column += strlen(configtext);
// Column += m_strlen(configtext);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Column += m_strlen(configtext);


configlval.nval.i = atoi(configtext);

Expand All @@ -678,7 +679,7 @@ bool do_float()

{

// Column += strlen(configtext);
// Column += m_strlen(configtext);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Column += m_strlen(configtext);


configlval.nval.d = atof(configtext);

Expand Down Expand Up @@ -1113,7 +1114,7 @@ int do_comp()

int return_value = 0;

Column += strlen(configtext);
Column += m_strlen(configtext);

if ( strcmp(configtext, "<" ) == 0 ) { configlval.cval = thresh_lt; return_value = COMPARISON; }
else if ( strcmp(configtext, ">" ) == 0 ) { configlval.cval = thresh_gt; return_value = COMPARISON; }
Expand Down
1 change: 1 addition & 0 deletions met/src/basic/vx_log/concat_string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ void ConcatString::assign(const ConcatString & c)

memcpy(FloatFormat, c.FloatFormat, sizeof(FloatFormat));
Precision = c.Precision;
AllocInc = c.AllocInc;
}


Expand Down
27 changes: 18 additions & 9 deletions met/src/basic/vx_util/ascii_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ using namespace std;
#include "ascii_table.h"
#include "comma_string.h"
#include "fix_float.h"
#include "string_fxns.h"
#include "util_constants.h"

////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1319,6 +1320,13 @@ if ( Nrows < 0 || Nrows >= INT_MAX ) {
exit ( 1 );
}

//
// Line up the decimals in the data starting in row 2.
// For two or fewer rows, there is no work to do.
//

if ( Nrows <= 2 ) return;

int left[Nrows];
int right[Nrows];

Expand All @@ -1327,23 +1335,24 @@ int max_left, max_right;
const char fill_char = ' ';
const int r_start = 1; // skip the header row


for (r=0; r<r_start; ++r) {

left[r] = right[r] = 0;

}

for (c=0; c<Ncols; ++c) {

// get the pad size for that column

max_left = max_right = -5; // negative value as the minimum offset of the text

for (r=r_start; r<Nrows; ++r) {

n = rc_to_n(r, c);

n_figures(e[n], left[r], right[r]);

}

max_left = left [r_start];
max_right = right [r_start];

for (r=r_start+1; r<Nrows; ++r) {

if ( left [r] > max_left ) max_left = left[r];
if ( right [r] > max_right ) max_right = right[r];

Expand Down Expand Up @@ -1525,7 +1534,7 @@ out[field_width] = (char) 0; // end-of-string marker

if ( !text ) return;

len = strlen(text);
len = m_strlen(text);

if ( len == 0 ) return;

Expand Down
4 changes: 1 addition & 3 deletions met/src/basic/vx_util/command_line.cc
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ for (j=0; j<N; ++j) {
//

if ( (args[j].compare(verbosity_option) == 0) ||
(args[j].compare(log_option) == 0) ) continue;
(args[j].compare(log_option) == 0) ) continue;

option_index = options.lookup(args[j]);

Expand All @@ -750,8 +750,6 @@ for (j=0; j<N; ++j) {

}

return ( j );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know the logic here, but did you intend to remove this return?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The line 753 can not be executed because of the if statement above: continue or exit( 1 )

      if ( AllowUnrecognizedSwitches )  continue;
      else {
         mlog << Error << "\nCommandLine::next_option() -> "
              << "unrecognized command-line switch \"" << args[j] << "\"\n\n";
         exit ( 1 );
      }
      return ( j );  <-- not reachable


}

} // for j
Expand Down
2 changes: 1 addition & 1 deletion met/src/basic/vx_util/filename_suffix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const char * f = get_short_name(filename); // to avoid things like "./foo"
// start at the end of the filename
//

const char * s = f + (strlen(f) - 1);
const char * s = f + (m_strlen(f) - 1);

//
// move left until we see a period
Expand Down
9 changes: 5 additions & 4 deletions met/src/basic/vx_util/is_number.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ using namespace std;
#include <cmath>

#include "is_number.h"
#include "string_fxns.h"
#include "substring.h"


Expand All @@ -46,7 +47,7 @@ static int is_allowed_float_char(const char c);

static const char allowed_float_chars [] = "+-Ee.0123456789";

static const int n_allowed_float_chars = strlen(allowed_float_chars);
static const int n_allowed_float_chars = m_strlen(allowed_float_chars);


////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -112,7 +113,7 @@ int is_float(const char * text)

if ( !text ) return ( 0 );

const int n = strlen(text);
const int n = m_strlen(text);

if ( n == 0 ) return ( 0 );

Expand Down Expand Up @@ -184,7 +185,7 @@ if ( is_sign_char(t[0]) ) ++t;
// at most one decimal point
//

n = strlen(t);
n = m_strlen(t);

digit_count = dp_count = 0;

Expand Down Expand Up @@ -226,7 +227,7 @@ char junk[128];
// if the "e" is the first or last character, return "no"
//

n = strlen(text);
n = m_strlen(text);

if ( (exp_pos == 0) || (exp_pos == (n - 1)) ) return ( 0 );

Expand Down
33 changes: 17 additions & 16 deletions met/src/basic/vx_util/make_path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ using namespace std;

#include "make_path.h"
#include "vx_log.h"
#include "string_fxns.h"


////////////////////////////////////////////////////////////////////////
Expand All @@ -46,40 +47,40 @@ if ( path_exists(path) ) return ( 1 );

int j;
int status;
char subpath[PATH_MAX];
const char *method_name = "make_path() ";


memset(subpath, 0, sizeof(subpath));

//
// make subpath
//

strcpy(subpath, path);

j = strlen(subpath) - 1;

while ( (j >= 0) && (subpath[j] != '/') ) subpath[j--] = (char) 0;
char *subpath = m_strcpy2(path, method_name);

if ( j >= 0 ) subpath[j] = (char) 0;
if (subpath) {
j = m_strlen(subpath) - 1;

mlog << Debug(1) << "\n\n subpath = \"" << subpath << "\"\n\n";
while ( (j >= 0) && (subpath[j] != '/') ) subpath[j--] = (char) 0;

if ( strlen(subpath) == 0 ) return ( 0 );
if ( j >= 0 ) subpath[j] = (char) 0;

mlog << Debug(1) << "\n\n " << method_name << "subpath = \"" << subpath << "\"\n\n";

if ( m_strlen(subpath) == 0 ) {
if (subpath) { delete [] subpath; subpath = (char *) 0; }
return ( 0 );
}

if ( !(path_exists(subpath)) ) {

make_path(subpath, mode);
if ( !(path_exists(subpath)) ) {
make_path(subpath, mode);
}

}


status = mkdir(path, mode);

if ( status < 0 ) return ( 0 );
if (subpath) { delete [] subpath; subpath = (char *) 0; }

if ( status < 0 ) return ( 0 );

return ( 1 );

Expand Down
Loading