Commit 9052d96a authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent d20e0353
......@@ -242,5 +242,22 @@ tuple<uint64_t, error> parseHex64(const string& s) {
return make_tuple(v, nil);
}
// paeseInt decodes string s as signed decimal integer.
tuple<int64_t, error> parseInt(const string& s) {
int64_t v;
int n = sscanf(s.c_str(), "%" SCNi64, &v); // XXX verify
if (!(n == 1 && std::to_string(v) == s)) // XXX verify
return make_tuple(0, fmt::errorf("int %s invalid", s.c_str()));
return make_tuple(v, nil);
}
// parseUint decodes string s as unsigned decimal integer.
tuple<uint64_t, error> parse_uint(const string& s) {
uint64_t v;
int n = sscanf(s.c_str(), "%" SCNu64, &v); // XXX verify
if (!(n == 1 && std::to_string(v) == s)) // XXX verify
return make_tuple(0, fmt::errorf("uint %s invalid", s.c_str()));
return make_tuple(v, nil);
}
} // xstrconv::
......@@ -201,6 +201,7 @@ namespace xstrconv {
tuple<uint64_t, error> parseHex64(const string& s);
tuple<int64_t, error> parseInt(const string& s);
tuple<uint64_t, error> parseUint(const string& s);
} // xstrconv
......
......@@ -42,7 +42,6 @@ using namespace golang;
#include <sys/stat.h>
#include <unistd.h>
#include <stdint.h>
#include <inttypes.h>
#include "wcfs_misc.h"
......@@ -767,8 +766,9 @@ error rxPkt::from_string(const string &rx) {
string sid = rx.substr(0, sp);
string smsg = rx.substr(sp+1);
sscanf(sid.c_str(), "%" SCNu64, &pkt.stream);
if (std::to_string(pkt.stream) != sid)
error err;
tie(pkt.stream, err) = xstrconv::parseUint(sid);
if (err != nil)
return fmt::errorf("invalid pkt: invalid stream ID");
auto msglen = smsg.length();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment