istream_helpers: Fix sscanf typo
diff mbox series

Message ID 20191007225732.12571-1-rosenp@gmail.com
State New
Headers show
Series
  • istream_helpers: Fix sscanf typo
Related show

Commit Message

Rosen Penev Oct. 7, 2019, 10:57 p.m. UTC
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(-)

Comments

Bernhard Reutner-Fischer Oct. 8, 2019, 6:07 a.m. UTC | #1
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,
Rosen Penev Oct. 10, 2019, 12:48 a.m. UTC | #2
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,

Patch
diff mbox series

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);
 					}