On Thu, 12 May 2022 15:58:57 GMT, Severin Gehwolf <sgehw...@openjdk.org> wrote:
>> src/hotspot/os/linux/cgroupV1Subsystem_linux.cpp line 113: >> >>> 111: } >>> 112: buf[MAXPATHLEN-1] = '\0'; >>> 113: _path = os::strdup(buf); >> >> I think this code can be simplified a lot with stringStream and without >> strtok, so no need for fixed buffers (which may fail with longer path names) >> and no need for writable string copies on the stack. >> >> Something like this: >> >> stringStream ss; >> ss.print_raw(_mount_point); >> const char* p1 = _root; >> const char* p2 = cgroup_path; >> int last_matching_dash_pos = -1; >> for (int i = 0; *p1 == *p2 && *p1 != 0; i ++) { >> if (*p1 == '/') { >> last_matching_dash_pos = i; >> } >> p1++; p2++; >> } >> ss.print_raw(_root, last_matching_dash_pos); >> // Now use ss.base() to access the assembled string > > Nice, thanks! I'll update it. Done. ------------- PR: https://git.openjdk.java.net/jdk/pull/8629