clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name path_util.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mthread-model posix -fno-delete-null-pointer-checks -mframe-pointer=all -relaxed-aliasing -fmath-errno -fno-rounding-math -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -dwarf-column-info -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib/llvm-10/lib/clang/10.0.0 -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/support/modules_include/java.base -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/support/modules_include/java.base/linux -I /home/daniel/Projects/java/jdk/src/java.base/share/native/libjava -I /home/daniel/Projects/java/jdk/src/java.base/unix/native/libjava -I /home/daniel/Projects/java/jdk/src/hotspot/share/include -I /home/daniel/Projects/java/jdk/src/hotspot/os/posix/include -D LIBC=gnu -D _GNU_SOURCE -D _REENTRANT -D _LARGEFILE64_SOURCE -D LINUX -D DEBUG -D _LITTLE_ENDIAN -D ARCH="amd64" -D amd64 -D _LP64=1 -D ARCHPROPNAME="amd64" -I /home/daniel/Projects/java/jdk/src/java.base/linux/native/libjava -I /home/daniel/Projects/java/jdk/src/java.base/unix/native/libjava -I /home/daniel/Projects/java/jdk/src/java.base/share/native/libjava -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/support/headers/java.base -I /home/daniel/Projects/java/jdk/src/java.base/share/native/libfdlibm -D _FORTIFY_SOURCE=2 -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-10/lib/clang/10.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wno-unused -Wno-unused-result -Wno-unused-function -std=c99 -fdebug-compilation-dir /home/daniel/Projects/java/jdk/make -ferror-limit 19 -fmessage-length 0 -fvisibility hidden -stack-protector 1 -fgnuc-version=4.2.1 -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -o /home/daniel/Projects/java/scan/2021-12-21-193737-8510-1 -x c /home/daniel/Projects/java/jdk/src/java.base/unix/native/libjava/path_util.c
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | #include <stdlib.h> |
| 27 | #include <string.h> |
| 28 | #if !defined(_ALLBSD_SOURCE) |
| 29 | #include <alloca.h> |
| 30 | #endif |
| 31 | |
| 32 | #include "path_util.h" |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | static int |
| 38 | collapsible(char *names) |
| 39 | { |
| 40 | char *p = names; |
| 41 | int dots = 0, n = 0; |
| 42 | |
| 43 | while (*p) { |
| 44 | if ((p[0] == '.') && ((p[1] == '\0') |
| 45 | || (p[1] == '/') |
| 46 | || ((p[1] == '.') && ((p[2] == '\0') |
| 47 | || (p[2] == '/'))))) { |
| 48 | dots = 1; |
| 49 | } |
| 50 | n++; |
| 51 | while (*p) { |
| 52 | if (*p == '/') { |
| 53 | p++; |
| 54 | break; |
| 55 | } |
| 56 | p++; |
| 57 | } |
| 58 | } |
| 59 | return (dots ? n : 0); |
| 60 | } |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | static void |
| 67 | splitNames(char *names, char **ix) |
| 68 | { |
| 69 | char *p = names; |
| 70 | int i = 0; |
| 71 | |
| 72 | while (*p) { |
| 6 | | Loop condition is false. Execution continues on line 72 | |
|
| 73 | ix[i++] = p++; |
| 74 | while (*p) { |
| 75 | if (*p == '/') { |
| 76 | *p++ = '\0'; |
| 77 | break; |
| 78 | } |
| 79 | p++; |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | static void |
| 89 | joinNames(char *names, int nc, char **ix) |
| 90 | { |
| 91 | int i; |
| 92 | char *p; |
| 93 | |
| 94 | for (i = 0, p = names; i < nc; i++) { |
| 95 | if (!ix[i]) continue; |
| 96 | if (i > 0) { |
| 97 | p[-1] = '/'; |
| 98 | } |
| 99 | if (p == ix[i]) { |
| 100 | p += strlen(p) + 1; |
| 101 | } else { |
| 102 | char *q = ix[i]; |
| 103 | while ((*p++ = *q++)); |
| 104 | } |
| 105 | } |
| 106 | *p = '\0'; |
| 107 | } |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | void |
| 116 | collapse(char *path) |
| 117 | { |
| 118 | char *names = (path[0] == '/') ? path + 1 : path; /' */ |
| 1 | Assuming the condition is false | |
|
| |
| 119 | int nc; |
| 120 | char **ix; |
| 121 | int i, j; |
| 122 | char *p, *q; |
| 123 | |
| 124 | nc = collapsible(names); |
| 125 | if (nc < 2) return; |
| |
| |
| 126 | ix = (char **)alloca(nc * sizeof(char *)); |
| 127 | splitNames(names, ix); |
| |
| 7 | | Returning from 'splitNames' | |
|
| 128 | |
| 129 | for (i = 0; i < nc; i++) { |
| 8 | | The value 0 is assigned to 'i' | |
|
| 9 | | Loop condition is true. Entering loop body | |
|
| 130 | int dots = 0; |
| 131 | |
| 132 | |
| 133 | do { |
| 134 | char *p = ix[i]; |
| 10 | | Assigned value is garbage or undefined |
|
| 135 | if (p[0] == '.') { |
| 136 | if (p[1] == '\0') { |
| 137 | dots = 1; |
| 138 | break; |
| 139 | } |
| 140 | if ((p[1] == '.') && (p[2] == '\0')) { |
| 141 | dots = 2; |
| 142 | break; |
| 143 | } |
| 144 | } |
| 145 | i++; |
| 146 | } while (i < nc); |
| 147 | if (i >= nc) break; |
| 148 | |
| 149 | |
| 150 | |
| 151 | if (dots == 1) { |
| 152 | |
| 153 | ix[i] = 0; |
| 154 | } |
| 155 | else { |
| 156 | |
| 157 | |
| 158 | for (j = i - 1; j >= 0; j--) { |
| 159 | if (ix[j]) break; |
| 160 | } |
| 161 | if (j < 0) continue; |
| 162 | ix[j] = 0; |
| 163 | ix[i] = 0; |
| 164 | } |
| 165 | |
| 166 | } |
| 167 | |
| 168 | joinNames(names, nc, ix); |
| 169 | } |