On 10/12/14 15:46, Ulrich Mueller wrote:
On Sun, 12 Oct 2014, Dan Douglas wrote:
On Sun, Oct 12, 2014 at 11:22 AM, Anthony G. Basile <[email protected]> wrote:
+# Returns true if gcc builds with fstack-check
+gcc-specs-stack-check() {
+    local directive
+    directive=$(gcc-specs-directive cc1)
+    return $([[ "${directive/\{!fno-stack-check:}" != "${directive}" ]])
+}
Am I missing something here? I don't see how any of the tests used
in gcc-specs-* functions could possibly produce an output. The fact
that this coincidentally works in Bash shouldn't be relied upon.
The command produces no output, so return is effectively called
without argument. Therefore it will return with the status of the last
command executed, which is [[ ]] ...

It would be clearer if the last line of the function was simply this:
     [[ "${directive/\{!fno-stack-check:}" != "${directive}" ]]

Ulrich

Yeah the return there is useless and in fact deceiving. Its returning a blank with an error code. Here's some bash to illustrate:

do_true() {
 return $([[ 42 == 42 ]])
}

do_false() {
 return $([[ 42 != 42 ]])
 }

do_true   # echo's nothing

do_false  # echo's nothing

do_true ; echo $?
0

do_false ; echo $?
1

I can fix my function as well as the other gcc-specs-* in there, which I just copied. I'll produce two patches for the community's approval before committing anything. However, we'd better grep the tree for those gcc-specs-* functions just in case something subtle is going on.

--
Anthony G. Basile, Ph.D.
Gentoo Linux Developer [Hardened]
E-Mail    : [email protected]
GnuPG FP  : 1FED FAD9 D82C 52A5 3BAB  DC79 9384 FA6E F52D 4BBA
GnuPG ID  : F52D4BBA


Reply via email to