@{$missing_flags_ref} = @missing_flags;
return 0;
}
+# Check if any of \@bad_flags occurs after $good_flag. Doesn't check if
+# $good_flag is present.
+sub flag_overwritten {
+ my ($line, $good_flag, $bad_flags) = @_;
-sub cppflags_fortify_broken {
- my ($line, $missing_flags) = @_;
-
- if (not any_flags_used($line, @def_cppflags_fortify_bad)) {
+ if (not any_flags_used($line, @{$bad_flags})) {
return 0;
}
- # $def_cppflags_fortify[0] must be -D_FORTIFY_SOURCE=2!
- my $fortify_source = $def_cppflags_fortify[0];
-
- # Some build systems enable/disable fortify source multiple times, check
- # the final result.
- my $disable_pos = 0;
- foreach my $flag (@def_cppflags_fortify_bad) {
+ my $bad_pos = 0;
+ foreach my $flag (@{$bad_flags}) {
while ($line =~ /$flag/g) {
- if ($disable_pos < $+[0]) {
- $disable_pos = $+[0];
+ if ($bad_pos < $+[0]) {
+ $bad_pos = $+[0];
}
}
}
- my $enable_pos = 0;
- while ($line =~ /$fortify_source/g) {
- $enable_pos = $+[0];
+ my $good_pos = 0;
+ while ($line =~ /$good_flag/g) {
+ $good_pos = $+[0];
}
- if ($enable_pos > $disable_pos) {
+ if ($good_pos > $bad_pos) {
return 0;
}
+ return 1;
+}
+sub cppflags_fortify_broken {
+ my ($line, $missing_flags) = @_;
+
+ # $def_cppflags_fortify[0] must be -D_FORTIFY_SOURCE=2!
+ my $fortify_source = $def_cppflags_fortify[0];
+
+ # Some build systems enable/disable fortify source multiple times, check
+ # the final result.
+ if (not flag_overwritten($line,
+ $fortify_source,
+ \@def_cppflags_fortify_bad)) {
+ return 0;
+ }
push @{$missing_flags}, $fortify_source;
return 1;
}