delorie.com/archives/browse.cgi | search |
X-Recipient: | archive-cygwin AT delorie DOT com |
DomainKey-Signature: | a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id |
:list-unsubscribe:list-subscribe:list-archive:list-post | |
:list-help:sender:mime-version:content-type | |
:content-transfer-encoding:message-id:date:from:to:subject | |
:in-reply-to:references; q=dns; s=default; b=Mr8VFkB89SfWwDomJ9t | |
mV0b0wujl5lR6ZuJSjh5pEALubfDl4BYmn1NbtDyPAA/QnvOR3FEoqmoOtrKJyAz | |
Vrnr83hkDXVQ7aRlwwyFNcNo3OX0HcGaWkRu4IKuaNLnEiaxUbZcJh8pAL7I7JaQ | |
hHRgFqxxKuK+rPvUm6bzOZFY= | |
DKIM-Signature: | v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id |
:list-unsubscribe:list-subscribe:list-archive:list-post | |
:list-help:sender:mime-version:content-type | |
:content-transfer-encoding:message-id:date:from:to:subject | |
:in-reply-to:references; s=default; bh=xGZBc2DZNaX311NT24YcuoaDi | |
W0=; b=mN/JLVsCROmr9ds8mDa0ClpPW5MUG7mI5m1uRM6C7GwNyyv4JAYYuLva0 | |
6yuHuj7rOyt3MwIhVH4gZ5kFYQbRRstyJmTaN2kblDcmhNjO8+TLaTDdB0XTxEkz | |
Y2uc3R3gbp5Yr7XB2HeQloiHYXomv59xX8GdWucpqqdLsFGPCo= | |
Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm |
List-Id: | <cygwin.cygwin.com> |
List-Subscribe: | <mailto:cygwin-subscribe AT cygwin DOT com> |
List-Archive: | <http://sourceware.org/ml/cygwin/> |
List-Post: | <mailto:cygwin AT cygwin DOT com> |
List-Help: | <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs> |
Sender: | cygwin-owner AT cygwin DOT com |
Mail-Followup-To: | cygwin AT cygwin DOT com |
Delivered-To: | mailing list cygwin AT cygwin DOT com |
Authentication-Results: | sourceware.org; auth=none |
X-Virus-Found: | No |
X-Spam-SWARE-Status: | Yes, score=5.7 required=5.0 tests=AWL,BAYES_50,BODY_8BITS,GARBLED_BODY,HK_RANDOM_ENVFROM,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 |
X-HELO: | sneak2.sneakemail.com |
MIME-Version: | 1.0 |
Message-ID: | <29330-1448212954-184938@sneakemail.com> |
Date: | Sun, 22 Nov 2015 10:22:29 -0700 |
From: | "John Hein" <3fbmqnhaz4 AT snkmail DOT com> |
To: | cygwin AT cygwin DOT com |
Subject: | Re: Errors in handling of boost::asio errors ('boost' was compiled with wrong std::string representation?) |
In-Reply-To: | <web-32611685@mx27.intranet.ru> |
References: | <web-32611685 AT mx27 DOT intranet DOT ru> |
X-MIME-Autoconverted: | from quoted-printable to 8bit by delorie.com id tAMHMonV001219 |
Роман 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
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |