delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2022/07/02/17:34:58

X-Recipient: archive-cygwin AT delorie DOT com
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 653E4385828E
Authentication-Results: sourceware.org;
dmarc=none (p=none dis=none) header.from=dinwoodie.org
Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=dinwoodie.org
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=dinwoodie.org; s=google;
h=date:from:to:subject:message-id:reply-to:references:mime-version
:content-disposition:in-reply-to;
bh=WcVgnZdRyvKNwt3CuPK7dLPrr+iffJfBV+MVCw6pSiE=;
b=dQLybd2DFUlVJ3QAIQVKduBouiTVPk+kFzjvV1/evzPvmrym63DZtvTGaRjvVreIrO
5doyPs0KokhJTzgrYhu8aqXEhAXBVZP+D1P3BAzAEhBew0w7SVW/WkUxURq3fYmMCN3y
Or2kS4DYvAZ1SLc6Sh17QvX/pm797taAeJ5+U=
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=x-gm-message-state:date:from:to:subject:message-id:reply-to
:references:mime-version:content-disposition:in-reply-to;
bh=WcVgnZdRyvKNwt3CuPK7dLPrr+iffJfBV+MVCw6pSiE=;
b=H9FKk8kHVsP9tqiC84/P5/5WLtGzmb2D0pGm7h43qFUPTH5R65FqYy8mc32Pr8EGg2
G0l/i7hbghj1FrtXWydU9YoG1h0qXCJglOxd2073Snl1NXYIlJ2nFgklTAkhEO5Ur+Ay
GpiM+5y9Rrl6e7KNlT828NSsQ2CzbxvFTm1qa1rCM2NxJEFBFUeIhLxy918M4KLDqQ5K
5CQoQKi5nP9uC6Yg2NrM/pUtak/fpn0cs/k3aBV8dbCHeIa54xhtxt0REaKAq+wBcN7L
DTBs1zeQ9L5tyWy7I2xOG7E1RzryJUrqsoAXb0Sn158dJ4xRO6devReohCk6emrYfohp
W5qw==
X-Gm-Message-State: AJIora8d+KZX6RNCw4EpbYa2I3toyr1vZ6YjeH5MSi5QfLaUhGOBnwo6
eGAnn0jIvi0xVtdA6YZIUUfritzXN0Lm8w==
X-Google-Smtp-Source: AGRyM1s5PfGstrPINs1VL9OKDHvNNOeojfF3zUKGg1KpAdJYAQEGDIGLDRe3hvHEDEh3blwcQTAxKQ==
X-Received: by 2002:a5d:648c:0:b0:21d:1475:8b68 with SMTP id
o12-20020a5d648c000000b0021d14758b68mr19131388wri.588.1656797677000;
Sat, 02 Jul 2022 14:34:37 -0700 (PDT)
Date: Sat, 2 Jul 2022 22:34:35 +0100
From: Adam Dinwoodie <adam AT dinwoodie DOT org>
To: cygwin AT cygwin DOT com
Subject: Re: Unexpected zero return code from `throw std::runtime_error`
Message-ID: <20220702213435.hkdcsjm7jzbc7im4@lucy.dinwoodie.org>
References: <20220702132158 DOT g6u7wo2lnokgezoc AT lucy DOT dinwoodie DOT org>
<CAEhDDbCDj9bKLoJUbi4eOdA+Rx-jnA1eyJkkA583OQqyi_702w AT mail DOT gmail DOT com>
MIME-Version: 1.0
In-Reply-To: <CAEhDDbCDj9bKLoJUbi4eOdA+Rx-jnA1eyJkkA583OQqyi_702w@mail.gmail.com>
X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00, DKIM_SIGNED,
DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,
SPF_PASS, TXREP,
T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6
X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on
server2.sourceware.org
X-BeenThere: cygwin AT cygwin DOT com
X-Mailman-Version: 2.1.29
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-request AT cygwin DOT com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=subscribe>
Reply-To: cygwin AT cygwin DOT com
Errors-To: cygwin-bounces+archive-cygwin=delorie DOT com AT cygwin DOT com
Sender: "Cygwin" <cygwin-bounces+archive-cygwin=delorie DOT com AT cygwin DOT com>

On Sat, Jul 02, 2022 at 10:19:44PM +0200, Csaba Raduly wrote:
> On Sat, 2 Jul 2022 at 15:22, Adam Dinwoodie  wrote:
> >
> > I'm currently experimenting with compiling rdfind for Cygwin, and one of
> > the testcases is failing because std::runtime_error is expected to
> > result in the compiled program exiting with a non-zero return code,
> > but on Cygwin, it just seems to cause the program to terminate with a
> > zero return code.
> >
> > I've attached a simple test case.  Compare the output on Cygwin...
> >
> >     $ ./test.sh
> >     + cat
> >     + g++ test.cc
> >     + [[ -x a.exe ]]
> >     + ./a.exe
> >     + rc=0
> >     + ((  rc == 0  ))
> >     + echo 'Unexpected zero return code from execution'
> >     Unexpected zero return code from execution
> >     + exit 1
> >
> > ...with the output from one of my Debian boxes...
> >
> >     $ ./test.sh
> >     + cat
> >     + g++ test.cc
> >     + [[ -x a.exe ]]
> >     + [[ -x a.out ]]
> >     + ./a.out
> >     terminate called after throwing an instance of 'std::runtime_error'
> >       what():  Test error
> >     ./test.sh: line 21: 566327 Aborted                 ./a.out
> >     + rc=134
> >     + ((  rc == 0  ))
> >     + echo 'Expected non-zero return code received: 134'
> >     Expected non-zero return code received: 134
> >     + exit 0
> >
> > I'm not massively familiar with C++, so I could well be missing
> > something obvious, but this seems like an unexpected difference between
> > Cygwin and other *nix platforms.  Is this a Cygwin bug, or am I doing
> > something wrong?
> 
> 
> Works just fine for me, unless I misunderstood something.
> 
> $ /cygdrive/c/Users/Csaba/Downloads/test.sh
> + cat
> + g++ test.cc
> + [[ -x a.exe ]]
> + ./a.exe
> terminate called after throwing an instance of 'std::runtime_error'
>   what():  Test error
> /cygdrive/c/Users/Csaba/Downloads/test.sh: line 21:   641 Aborted
>            (core dumped) ./a.exe
> + rc=134
> + ((  rc == 0  ))
> + echo 'Expected non-zero return code received: 134'
> Expected non-zero return code received: 134
> + exit 0

That's definitely closer to the behaviour I'd expect!  I don't think it
should be dumping a core, though, at least based on the behaviour I see
on Debian.

I'd like to have a look at what's different about your environment;
could you share the output from `cygcheck -srv >cygcheck.out` on your
system?

> The if goes in the "else" case because rc is not 0, as it should be.
> (shoudn't the condition be $rc == 0 ?)
> After
> 
> $ diff -u /cygdrive/c/Users/Csaba/Downloads/test.sh test.sh
> --- /cygdrive/c/Users/Csaba/Downloads/test.sh   2022-07-02
> 22:09:21.506377100 +0200
> +++ test.sh     2022-07-02 22:15:08.670809700 +0200
> @@ -20,7 +20,8 @@
>         exit 2
>  fi
> 
> -if (( rc == 0 )); then
> +if [[ $rc == 0 ]]
> +then
>         echo 'Unexpected zero return code from execution'
>         exit 1
>  else
> 
> I get
> 
> $ ./test.sh
> + cat
> + g++ test.cc
> + [[ -x a.exe ]]
> + ./a.exe
> terminate called after throwing an instance of 'std::runtime_error'
>   what():  Test error
> ./test.sh: line 21:   660 Aborted                 (core dumped) ./a.exe
> + rc=134
> + [[ 134 == 0 ]]
> + echo 'Expected non-zero return code received: 134'
> Expected non-zero return code received: 134
> + exit 0

`(( rc == 0 ))` is comparing the value of `$rc` against the number 0;
the `$` isn't necessary in `(( ... ))` tests.  `(( rc == 0 ))` is
essentially identical to `[[ $rc -eq 0 ]]`.

Your change means the comparison is done as a string comparison rather
than a numeric comparison.  That doesn't make any difference here: '0'
is '0' regardless of whether you're testing it as a number or as a
string.

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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019