Skip to content

Commit cc757cf

Browse files
authored
misc: Fix buggy special path comparisons (#270)
This patch fixes the buggy special path comparisons in src/kern/linux/linux.cc Linux::openSpecialFile(), which only checked for equality of path prefixes, but not equality of the paths themselves. This patch replaces those buggy comparisons with regular std::string::operator== string equality comparisons. GitHub issue: gem5/gem5#269
2 parents 5d98d18 + 3dfdd48 commit cc757cf

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/kern/linux/linux.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,19 @@ Linux::openSpecialFile(std::string path, Process *process,
5858
bool matched = false;
5959
std::string data;
6060

61-
if (path.compare(0, 13, "/proc/meminfo") == 0) {
61+
if (path == "/proc/meminfo") {
6262
data = Linux::procMeminfo(process, tc);
6363
matched = true;
64-
} else if (path.compare(0, 11, "/etc/passwd") == 0) {
64+
} else if (path == "/etc/passwd") {
6565
data = Linux::etcPasswd(process, tc);
6666
matched = true;
67-
} else if (path.compare(0, 15, "/proc/self/maps") == 0) {
67+
} else if (path == "/proc/self/maps") {
6868
data = Linux::procSelfMaps(process, tc);
6969
matched = true;
70-
} else if (path.compare(0, 30, "/sys/devices/system/cpu/online") == 0) {
70+
} else if (path == "/sys/devices/system/cpu/online") {
7171
data = Linux::cpuOnline(process, tc);
7272
matched = true;
73-
} else if (path.compare(0, 12 ,"/dev/urandom") == 0) {
73+
} else if (path == "/dev/urandom") {
7474
data = Linux::devRandom(process, tc);
7575
matched = true;
7676
}

0 commit comments

Comments
 (0)