Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cdo
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mpim-sw
cdo
Commits
6f2b1868
Commit
6f2b1868
authored
3 years ago
by
Uwe Schulzweida
Browse files
Options
Downloads
Patches
Plain Diff
KVListAppendNamelist: replace snprintf() my memcpy()
parent
955e4068
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Pipeline
#8633
passed
3 years ago
Stage: build
Stage: check
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ChangeLog
+4
-0
4 additions, 0 deletions
ChangeLog
src/pmlist.cc
+5
-16
5 additions, 16 deletions
src/pmlist.cc
with
9 additions
and
16 deletions
ChangeLog
+
4
−
0
View file @
6f2b1868
...
...
@@ -6,6 +6,10 @@
2021-06-14 Uwe Schulzweida
* KVListAppendNamelist: replace snprintf() my memcpy()
2021-06-13 Uwe Schulzweida
* New median operators - ensmedian, fldmedian, mermedian, zonmedian, gridboxmedian
* New skewness operators - ensskew, fldskew, merskew, zonskew, gridboxskew
* New kurtosis operators - enskurt, fldkurt, merkurt, zonkurt, gridboxkurt
...
...
This diff is collapsed.
Click to expand it.
src/pmlist.cc
+
5
−
16
View file @
6f2b1868
...
...
@@ -153,7 +153,6 @@ PMList::getKVListVentry(const std::vector<std::string> &entry)
static
void
KVListAppendNamelist
(
KVList
&
kvlist
,
const
char
*
key
,
const
char
*
buffer
,
NamelistToken
*
t
,
int
nvalues
,
bool
cdocmor
)
{
char
vbuf
[
4096
];
std
::
vector
<
char
>
value
;
KeyValues
kv
;
kv
.
key
=
key
;
...
...
@@ -166,16 +165,8 @@ KVListAppendNamelist(KVList &kvlist, const char *key, const char *buffer, Nameli
/** CMOR_MAX_STRING cannot be used **/
if
(
cdocmor
&&
len
>
1024
)
cdo_abort
(
"A string value is larger than the maximum size allowed by CMOR (1024 signs)."
);
value
.
resize
(
len
+
1
);
// printf(" value[%d] >%.*s<\n", i, (int)len, buffer+t[i].start);
auto
pval
=
buffer
+
t
[
i
].
start
;
if
(
len
<
sizeof
(
vbuf
))
// snprintf seems to call strlen(pval)
{
memcpy
(
vbuf
,
buffer
+
t
[
i
].
start
,
len
);
vbuf
[
len
]
=
0
;
pval
=
vbuf
;
}
if
(
value
.
size
()
<
(
len
+
1
)
)
value
.
resize
(
len
+
1
);
const
auto
pval
=
buffer
+
t
[
i
].
start
;
if
(
cdocmor
&&
strcmp
(
key
,
"code"
)
==
0
&&
!
strstr
(
pval
,
","
))
{
...
...
@@ -184,14 +175,12 @@ KVListAppendNamelist(KVList &kvlist, const char *key, const char *buffer, Nameli
if
(
code
>
0
&&
code
<
1000
)
snprintf
(
value
.
data
(),
4
,
"%03ld"
,
code
);
else
{
cdo_warning
(
"In parsing a line of a file:
\n
"
"Codes could not be transformed into the code format (three digit integer). Codes wont be used."
);
}
cdo_warning
(
"In parsing a line of a file:
\n
"
"Codes could not be transformed into the code format (three digit integer). Codes wont be used."
);
}
else
{
snprintf
(
value
.
data
(),
len
+
1
,
"%.*s"
,
(
int
)
len
,
pval
);
memcpy
(
value
.
data
(),
pval
,
len
);
value
[
len
]
=
0
;
}
kv
.
values
[
i
]
=
value
.
data
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment