cb424d7448
verify-patch-sanity.py validates every active recipe .patch has internally- consistent hunk line counts — catching the 'malformed patch at line N' failure at commit/CI/preflight time instead of hours into a cook. This cycle hit that class three times (qtwaylandscanner, sddm, xwayland), each only discovered when cookbook tried to apply the patch. Running it across the repo found 29 latent malformed patches (validated against GNU patch: e.g. relibc/P3-sysv-ipc reproduces 'malformed patch at line 22'). They were harmless only because they sit in vendored recipes (baked, not re- applied) — but would fail on any version-bump re-derivation. --fix recounts the hunk headers (body untouched) and repaired all 29. Wired into build-preflight.sh (Phase 1.0D) and redbear-ci.yml, with a unit test (test-patch-sanity.sh). Skips archived/legacy trees and unvalidatable formats (empty placeholders, bare-@@ git hunks).
90 lines
2.9 KiB
C
90 lines
2.9 KiB
C
// RUN: %clang_analyze_cc1 -verify %s \
|
|
// RUN: -analyzer-checker=core,unix.StdCLibraryFunctions \
|
|
// RUN: -analyzer-config unix.StdCLibraryFunctions:ModelPOSIX=true \
|
|
// RUN: -analyzer-output=text
|
|
|
|
#include "Inputs/std-c-library-functions-POSIX.h"
|
|
#define NULL ((void *)0)
|
|
|
|
char *getenv(const char *);
|
|
int isalpha(int);
|
|
int isdigit(int);
|
|
int islower(int);
|
|
|
|
char test_getenv() {
|
|
char *env = getenv("VAR"); // \
|
|
// expected-note{{Assuming the environment variable does not exist}} \
|
|
// expected-note{{'env' initialized here}}
|
|
|
|
return env[0]; // \
|
|
// expected-warning{{Array access (from variable 'env') results in a null pointer dereference}} \
|
|
// expected-note {{Array access (from variable 'env') results in a null pointer dereference}}
|
|
}
|
|
|
|
int test_isalpha(int *x, char c, char d) {
|
|
int iad = isalpha(d);
|
|
if (isalpha(c)) {// \
|
|
// expected-note{{Taking true branch}}
|
|
x = NULL; // \
|
|
// expected-note{{Null pointer value stored to 'x'}}
|
|
}
|
|
|
|
return *x; // \
|
|
// expected-warning{{Dereference of null pointer (loaded from variable 'x')}} \
|
|
// expected-note {{Dereference of null pointer (loaded from variable 'x')}}
|
|
}
|
|
|
|
int test_isdigit(int *x, char c) {
|
|
if (!isdigit(c)) {// \
|
|
// expected-note{{Taking true branch}}
|
|
x = NULL; // \
|
|
// expected-note{{Null pointer value stored to 'x'}}
|
|
}
|
|
|
|
return *x; // \
|
|
// expected-warning{{Dereference of null pointer (loaded from variable 'x')}} \
|
|
// expected-note {{Dereference of null pointer (loaded from variable 'x')}}
|
|
}
|
|
|
|
int test_islower(int *x) {
|
|
char c = 'c';
|
|
// No "Assuming..." note. We aren't assuming anything. We *know*.
|
|
if (islower(c)) { // \
|
|
// expected-note{{Taking true branch}}
|
|
x = NULL; // \
|
|
// expected-note{{Null pointer value stored to 'x'}}
|
|
}
|
|
|
|
return *x; // \
|
|
// expected-warning{{Dereference of null pointer (loaded from variable 'x')}} \
|
|
// expected-note {{Dereference of null pointer (loaded from variable 'x')}}
|
|
}
|
|
|
|
int test_bugpath_notes(FILE *f1, char c, FILE *f2) {
|
|
// This test has the purpose of checking that notes appear at correct place.
|
|
long a = ftell(f2); // no note
|
|
if (a == -1) // \
|
|
// expected-note{{Taking false branch}}
|
|
return -1;
|
|
int l = islower(c); // no note
|
|
a = ftell(f1); // \
|
|
// expected-note{{Value assigned to 'a'}} \
|
|
// expected-note{{Assuming that 'ftell' fails}}
|
|
return dup(a); // \
|
|
// expected-warning{{The 1st argument to 'dup' is -1 but should be >= 0}} \
|
|
// expected-note{{The 1st argument to 'dup' is -1 but should be >= 0}}
|
|
}
|
|
|
|
int test_fileno_arg_note(FILE *f1) {
|
|
return dup(fileno(f1)); // no warning
|
|
}
|
|
|
|
int test_readlink_bufsize_zero(char *Buf, size_t Bufsize) {
|
|
ssize_t Ret = readlink("path", Buf, Bufsize); // \
|
|
// expected-note{{Assuming that argument 'bufsize' is 0}} \
|
|
// expected-note{{'Ret' initialized here}}
|
|
return 1 / Ret; // \
|
|
// expected-warning{{Division by zero}} \
|
|
// expected-note{{Division by zero}}
|
|
}
|