[
https://issues.apache.org/jira/browse/MAPREDUCE-6005?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14080567#comment-14080567
]
Sean Zhong commented on MAPREDUCE-6005:
---------------------------------------
One more:
Can you also fix
{quote}
string StringUtil::ToString(int32_t v) {
char tmp[32];
snprintf(tmp, 32, "%d", v);
return tmp;
}
string StringUtil::ToString(uint32_t v) {
char tmp[32];
snprintf(tmp, 32, "%u", v);
return tmp;
}
string StringUtil::ToString(int64_t v) {
char tmp[32];
snprintf(tmp, 32, "%lld", (long long int)v);
return tmp;
}
string StringUtil::ToString(int64_t v, char pad, int64_t len) {
char tmp[32];
snprintf(tmp, 32, "%%%c%lldlld", pad, len);
return Format(tmp, v);
}
string StringUtil::ToString(uint64_t v) {
char tmp[32];
snprintf(tmp, 32, "%llu", (long long unsigned int)v);
return tmp;
}
string StringUtil::ToString(bool v) {
if (v) {
return "true";
} else {
return "false";
}
}
string StringUtil::ToString(float v) {
char tmp[32];
snprintf(tmp, 32, "%f", v);
return tmp;
}
string StringUtil::ToString(double v) {
char tmp[32];
snprintf(tmp, 32, "%lf", v);
return tmp;
}
{quote}
1) it is not safe to convert a char array to a string like this. It will
trigger a copy contructor. But by
http://www.cplusplus.com/reference/string/string/string/,
{quote}
string (const char* s);
the string need to be null terminated.
{quote}
2) snprintf(tmp, 32, "%lf", v) impl is platform dependant when size “32”
equals the v length. It may truncate the raw data, or may ignore the null
terminitor. http://linux.die.net/man/3/snprintf,
{quote}
The functions snprintf() and vsnprintf() write at most size bytes (including
the terminating null byte ('\0')) to str.
{quote}
> native-task: fix some valgrind errors
> --------------------------------------
>
> Key: MAPREDUCE-6005
> URL: https://issues.apache.org/jira/browse/MAPREDUCE-6005
> Project: Hadoop Map/Reduce
> Issue Type: Sub-task
> Components: task
> Reporter: Binglin Chang
> Assignee: Binglin Chang
> Attachments: MAPREDUCE-6005.v1.patch, MAPREDUCE-6005.v2.patch,
> MAPREDUCE-6005.v3.patch
>
>
> Running test with valgrind shows there are some bugs, this jira try to fix
> them.
--
This message was sent by Atlassian JIRA
(v6.2#6252)