public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Re: Errors in handling of boost::asio errors ('boost' was compiled with wrong std::string representation?)
@ 2015-11-23 16:32 Роман
  0 siblings, 0 replies; 4+ messages in thread
From: Роман @ 2015-11-23 16:32 UTC (permalink / raw)
  To: cygwin

John Hein wrote at 10:22 -0700 on Nov 22, 2015:
> Use 'size=%zu'.  And get into the habit of compiling with -Wall

1) My apology for inaccuracy.
2) Usually, I use -Wall, but omits it for brevity.
3) GCC cannot warn for "%zu" - "%lu" mismatch. But it can 
warn if I confuse "%u" with "%s".
4) The problem is still here:

--------------- begin of the code
#include <stdio.h>
#include <boost/asio.hpp>

int main()
{
     boost::asio::ip::address_v4 a;
     boost::system::error_code ec;
     a.from_string("127.0.0.1111", ec);

     std::string s = ec.message();

     printf("size=%zu, c_str=\"%s\".\n",
             s.size(),
             s.c_str());

     return 0;
}
--------------- end of the code

--------------- begin of the output
size=6444086549, c_str="Invalid argument".
--------------- end of the output

Windows 7, 64-bit, russian language.

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Errors in handling of boost::asio errors ('boost' was compiled with wrong std::string representation?)
@ 2015-11-24  8:18 Роман
  0 siblings, 0 replies; 4+ messages in thread
From: Роман @ 2015-11-24  8:18 UTC (permalink / raw)
  To: cygwin

If I use 'gcc-core', 'gcc-g++', 'libgcc1' and 'libstdc++6' 
all of version 4.9.2-3, all works OK.

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Errors in handling of boost::asio errors ('boost' was compiled with wrong std::string representation?)
  2015-11-21  5:33 Роман
@ 2015-11-22 17:22 ` John Hein
  0 siblings, 0 replies; 4+ messages in thread
From: John Hein @ 2015-11-22 17:22 UTC (permalink / raw)
  To: cygwin

Роман wrote at 11:33 +0600 on Nov 21, 2015:
 > Following program:
 > 
 > --------------- begin of code
 > #include <stdio.h>
 > #include <boost/system/error_code.hpp>
 > 
 > int main()
 > {
 >      std::string s = 
 > boost::system::generic_category().message(22);
 > 
 >      printf("size=%lu, c_str=\"%s\".\n",
 >              s.size(),
 >              s.c_str());
 > 
 >      return 0;
 > }
 > --------------- end of code
 > 
 > Give out following output:
 > 
 > --------------- begin of output
 > size=1628781863, c_str="Invalid argument".
 > --------------- end of output

Use 'size=%zu'.  And get into the habit of compiling with -Wall at
least.  That part has nothing to do with cygwin or boost (or windows
or ...).

That said, I can't reproduce your issue on win xp or win 7 / 32 bit
and boost 1.58.0-1, even when using %lu.  On those platforms size_t &
unsigned long are both 4 bytes.  I set LANG=ru_RU.UTF-8 before
compiling and running.  I didn't set up the windows environment
with any non-default language options.

Using '%z' would only matter (other than warnings) if the size of
size_t is not the same as the size of unsigned long.  In that case,
printf would interpret the wrong sizes for varargs parsing and would
print out garbage (and possibly crash depending on how lots of
variables played out).  In that case, I'd expect the string output to
be wrong as well.

 > If I try to use such string, for example:
 >    std::string a("");
 >    a += s;
 > program crashes.

Also works fine for me when I add those lines to the test program.


 > The program was compiled from cygwin command line by 
 > following commands:
 > 
 > --------------- begin of commands
 > g++ -c test.cpp
 > gcc -s test.o -lstdc++ -lboost_system
 > --------------- end of commands
 > 
 > I used fresh installed cygwin with following additional 
 > packages:
 >    Devel / gcc-core 5.2.0-1
 >    Devel / gcc-g++ 5.2.0-1
 >    Libs / libgcc1 5.2.0-1
 >    Libs / libstdc++6 5.2.0-1
 >    Devel / make 4.1-1
 >    Libs / libboost-devel 1.58.0-1
 > 
 > Operating system: Windows XP, 32 bits, russian language
 > Processor: Intel Pentium 4 (3 GHz)
 > Version of installator: setup-x86.exe, 2.873
 > 
 > With libboost-devel 1.57.0-1 effect is the same.
 > 
 > With Windows 7, 64 bit, russian language, effect is the 
 > same (with 32-bit and with 64-bit cygwin), with the 
 > exception that another wrong values are exposed for 
 > 'size'.
 > 
 > When I compile boost from sources ('boost_1_59_0.7z' from 
 > boost org), the same program is running as proper:
 > 
 > --------------- begin of correct output
 > size=16, c_str="Invalid argument".
 > --------------- end of correct output
 > 
 > Constant '22' corresponds to 
 > 'boost::asio::error::invalid_argument'. Some other ASIO 
 > error codes also brings to the same effect. Aforementioned 
 > code is used in handling of exceptions from ASIO functions 
 > and brings to crashes in various unpredictable situations.
 > 
 > There is more real-life piece of code that produce same 
 > error:
 > 
 > --------------- begin of example #2
 > #include <stdio.h>
 > #include <boost/asio.hpp>
 > 
 > int main()
 > {
 >      boost::asio::ip::address_v4 a;
 >      boost::system::error_code ec;
 >      a.from_string("127.0.0.1111", ec);
 > 
 >      std::string s = ec.message();
 > 
 >      printf("size=%lu, c_str=\"%s\".\n",
 >              s.size(),
 >              s.c_str());
 > 
 >      return 0;
 > }
 > --------------- end of example #2

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Errors in handling of boost::asio errors ('boost' was compiled with wrong std::string representation?)
@ 2015-11-21  5:33 Роман
  2015-11-22 17:22 ` John Hein
  0 siblings, 1 reply; 4+ messages in thread
From: Роман @ 2015-11-21  5:33 UTC (permalink / raw)
  To: cygwin

Following program:

--------------- begin of code
#include <stdio.h>
#include <boost/system/error_code.hpp>

int main()
{
     std::string s = 
boost::system::generic_category().message(22);

     printf("size=%lu, c_str=\"%s\".\n",
             s.size(),
             s.c_str());

     return 0;
}
--------------- end of code

Give out following output:

--------------- begin of output
size=1628781863, c_str="Invalid argument".
--------------- end of output

If I try to use such string, for example:
   std::string a("");
   a += s;
program crashes.

The program was compiled from cygwin command line by 
following commands:

--------------- begin of commands
g++ -c test.cpp
gcc -s test.o -lstdc++ -lboost_system
--------------- end of commands

I used fresh installed cygwin with following additional 
packages:
   Devel / gcc-core 5.2.0-1
   Devel / gcc-g++ 5.2.0-1
   Libs / libgcc1 5.2.0-1
   Libs / libstdc++6 5.2.0-1
   Devel / make 4.1-1
   Libs / libboost-devel 1.58.0-1

Operating system: Windows XP, 32 bits, russian language
Processor: Intel Pentium 4 (3 GHz)
Version of installator: setup-x86.exe, 2.873

With libboost-devel 1.57.0-1 effect is the same.

With Windows 7, 64 bit, russian language, effect is the 
same (with 32-bit and with 64-bit cygwin), with the 
exception that another wrong values are exposed for 
'size'.

When I compile boost from sources ('boost_1_59_0.7z' from 
boost org), the same program is running as proper:

--------------- begin of correct output
size=16, c_str="Invalid argument".
--------------- end of correct output

Constant '22' corresponds to 
'boost::asio::error::invalid_argument'. Some other ASIO 
error codes also brings to the same effect. Aforementioned 
code is used in handling of exceptions from ASIO functions 
and brings to crashes in various unpredictable situations.

There is more real-life piece of code that produce same 
error:

--------------- begin of example #2
#include <stdio.h>
#include <boost/asio.hpp>

int main()
{
     boost::asio::ip::address_v4 a;
     boost::system::error_code ec;
     a.from_string("127.0.0.1111", ec);

     std::string s = ec.message();

     printf("size=%lu, c_str=\"%s\".\n",
             s.size(),
             s.c_str());

     return 0;
}
--------------- end of example #2

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-11-24  4:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-23 16:32 Errors in handling of boost::asio errors ('boost' was compiled with wrong std::string representation?) Роман
  -- strict thread matches above, loose matches on Subject: below --
2015-11-24  8:18 Роман
2015-11-21  5:33 Роман
2015-11-22 17:22 ` John Hein

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).