Message ID | 20191007225732.12571-1-rosenp@gmail.com |
---|---|
State | New |
Headers | show |
Series | istream_helpers: Fix sscanf typo | expand |
On 8 October 2019 00:57:32 CEST, Rosen Penev <rosenp@gmail.com> wrote:
>This caused readin not to work properly with long long types.
Please add a testcase too.
TIA,
I tried adding a test case but I can't seem to get it to work This is what I have: a.str("0xFF 0xff 0x55"); a >> ll >> ull >> s; std::cout << "ll (should be 0xFF): " << ll << std::endl; std::cout << "ull (should be 0xff): " << ull << std::endl; It's not writing them properly. Maybe I misunderstand what the sscanf in the patch is supposed to do. On Mon, Oct 7, 2019 at 11:08 PM Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> wrote: > > On 8 October 2019 00:57:32 CEST, Rosen Penev <rosenp@gmail.com> wrote: > >This caused readin not to work properly with long long types. > > Please add a testcase too. > TIA,
diff --git a/include/istream_helpers b/include/istream_helpers index f2c793f..f8db903 100644 --- a/include/istream_helpers +++ b/include/istream_helpers @@ -317,7 +317,7 @@ namespace std{ sscanf(temp.c_str(), "%llo", (unsigned long long *)&var ); }else if(stream.flags() & ios_base::hex){ if(stream.flags() & ios_base::uppercase){ - scanf(temp.c_str(), "%llX", (unsigned long long *)&var ); + sscanf(temp.c_str(), "%llX", (unsigned long long *)&var ); }else{ sscanf(temp.c_str(), "%llx", (unsigned long long *)&var); } @@ -344,7 +344,7 @@ namespace std{ sscanf(temp.c_str(), "%llo", &var ); }else if(stream.flags() & ios_base::hex){ if(stream.flags() & ios_base::uppercase){ - scanf(temp.c_str(), "%llX", &var ); + sscanf(temp.c_str(), "%llX", &var ); }else{ sscanf(temp.c_str(), "%llx", &var); }
This caused readin not to work properly with long long types. Found accidentally through a glibc warning (declared with warn_unused_result). Tested with gptfdisk on OpenWrt. Signed-off-by: Rosen Penev <rosenp@gmail.com> --- include/istream_helpers | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)