cppcheck: member variable with name also defined in its parent class 'grib_accessor' [duplInheritedMember]

This commit is contained in:
shahramn 2024-10-11 11:31:39 +01:00
parent b28572ae64
commit bab87cfbfe
3 changed files with 18 additions and 14 deletions

View File

@ -16,11 +16,12 @@ grib_accessor* grib_accessor_to_double = &_grib_accessor_to_double;
void grib_accessor_to_double_t::init(const long len, grib_arguments* arg) void grib_accessor_to_double_t::init(const long len, grib_arguments* arg)
{ {
grib_accessor_gen_t::init(len, arg); grib_accessor_gen_t::init(len, arg);
grib_handle* hand = grib_handle_of_accessor(this);
key_ = grib_arguments_get_name(grib_handle_of_accessor(this), arg, 0); key_ = grib_arguments_get_name(hand, arg, 0);
start_ = grib_arguments_get_long(grib_handle_of_accessor(this), arg, 1); start_ = grib_arguments_get_long(hand, arg, 1);
length_ = grib_arguments_get_long(grib_handle_of_accessor(this), arg, 2); str_length_ = grib_arguments_get_long(hand, arg, 2);
scale_ = grib_arguments_get_long(grib_handle_of_accessor(this), arg, 3); scale_ = grib_arguments_get_long(hand, arg, 3);
if (!scale_) if (!scale_)
scale_ = 1; scale_ = 1;
@ -42,8 +43,8 @@ size_t grib_accessor_to_double_t::string_length()
{ {
size_t size = 0; size_t size = 0;
if (length_) if (str_length_)
return length_; return str_length_;
grib_get_string_length_acc(this, &size); grib_get_string_length_acc(this, &size);
return size; return size;
@ -62,15 +63,13 @@ long grib_accessor_to_double_t::get_native_type()
int grib_accessor_to_double_t::unpack_string(char* val, size_t* len) int grib_accessor_to_double_t::unpack_string(char* val, size_t* len)
{ {
int err = 0; int err = 0;
char buff[512] = { char buff[512] = {0,};
0,
};
size_t size = 512; size_t size = 512;
size_t length = string_length(); size_t length = string_length();
if (*len < length + 1) { if (*len < length + 1) {
grib_context_log(context_, GRIB_LOG_ERROR, "unpack_string: Wrong size (%lu) for %s, it contains %ld values", grib_context_log(context_, GRIB_LOG_ERROR, "unpack_string: Wrong size (%lu) for %s, it contains %ld values",
*len, name_, grib_accessor::length_ + 1); *len, name_, length + 1);
*len = length + 1; *len = length + 1;
return GRIB_ARRAY_TOO_SMALL; return GRIB_ARRAY_TOO_SMALL;
} }

View File

@ -32,7 +32,7 @@ public:
protected: protected:
const char* key_; const char* key_;
long start_; long start_;
size_t length_; size_t str_length_;
private: private:
long scale_; long scale_;

View File

@ -19,7 +19,7 @@ sample_grib2=$ECCODES_SAMPLES_PATH/GRIB2.tmpl
cat >$tempFilt<<EOF cat >$tempFilt<<EOF
transient aa = 156; transient aa = 156;
meta aad to_double(aa,0,3,0); meta aad to_double(aa,0,2,0); # substr "15"
print "aa=[aad]"; print "aa=[aad]";
transient xx = "45.5e3"; transient xx = "45.5e3";
@ -27,15 +27,20 @@ cat >$tempFilt<<EOF
print "xx=[xxd:d]"; print "xx=[xxd:d]";
transient yy = "45.9"; transient yy = "45.9";
meta yyd to_double(yy,0,2,0); meta yyd to_double(yy,0,2,0); # substr "45"
print "yy=[yyd:s]"; print "yy=[yyd:s]";
transient zz = "145.02";
meta zzd to_double(zz,1,4,0); # substr "45.0"
print "zz=[zzd:s]";
EOF EOF
${tools_dir}/grib_filter $tempFilt $sample_grib2 > $tempLog ${tools_dir}/grib_filter $tempFilt $sample_grib2 > $tempLog
cat >$tempRef<<EOF cat >$tempRef<<EOF
aa=156 aa=15
xx=45500 xx=45500
yy=45 yy=45
zz=45.0
EOF EOF
diff $tempRef $tempLog diff $tempRef $tempLog