Bug 137609 - webkitdirs::isCrossCompilation() cause Perl uninitialized warnings when using native GCC toolchain
Summary: webkitdirs::isCrossCompilation() cause Perl uninitialized warnings when using...
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-10-10 05:27 PDT by Adrien Destugues
Modified: 2016-04-25 21:00 PDT (History)
2 users (show)

See Also:


Attachments
Patch (1.58 KB, patch)
2014-10-10 05:32 PDT, Adrien Destugues
dbates: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Adrien Destugues 2014-10-10 05:27:15 PDT
webkitdirs.pm fails when CC is set to native compiler
Comment 1 Adrien Destugues 2014-10-10 05:32:51 PDT
Created attachment 239621 [details]
Patch
Comment 2 Daniel Bates 2016-04-25 21:00:42 PDT
Comment on attachment 239621 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=239621&action=review

> Tools/ChangeLog:12
> +        The perl regexp returns an empty array when there is no match (when
> +        the compiler in CC is not configured with --target or --host). Trying
> +        to test the first element of the array will trigger a warning
> +        "Use of uninitialized value $host[0] in string ne". Test that the
> +        array is not empty first.

Maybe a better way to describe the issue is to say:

Fixes an issue where webkitdirs::isCrossCompilation() causes Perl uninitialized warnings when the GCC compiler specified by the environment variable CC was not built for cross compilation.

> Tools/Scripts/webkitdirs.pm:1079
>        my @host = $compiler_options =~ m/--host=(.*?)\s/;
>        my @target = $compiler_options =~ m/--target=(.*?)\s/;
>  
> -      return ($host[0] ne "" && $target[0] ne "" && $host[0] ne $target[0]);
> +      return (@host && @target && $host[0] ne "" && $target[0] ne "" && $host[0] ne $target[0]);

We are underutilizing the use of an array for holding the captured output of the regular expressions because the regular expression on lines 1076 and 1077 each have exactly one capture group. Using the fact that a captured group is always a string and the property that the empty string evaluates to false in a boolean context, I would write this code as:

my $host = $1 if $compiler_options =~ /--host=(.*?)\s/;
my $target = $1 if $compiler_options =~ /--target=(.*?)\s/;
return ($host && $target && $host ne $target);