Skip to content

Commit 0ab8b34

Browse files
author
Andrew Savonichev
committed
Apply CR comments
Signed-off-by: Andrew Savonichev <[email protected]>
1 parent 27700f6 commit 0ab8b34

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

sycl/source/detail/os_util.cpp

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ OSModuleHandle OSUtil::getOSModuleHandle(const void *VirtAddr) {
8888
}
8989

9090
bool procMapsAddressInRange(std::istream &Stream, uintptr_t Addr) {
91-
uintptr_t Start, End;
91+
uintptr_t Start = 0, End = 0;
9292
Stream >> Start;
9393
assert(!Stream.fail() && Stream.peek() == '-' &&
9494
"Couldn't read /proc/self/maps correctly");
@@ -104,8 +104,8 @@ bool procMapsAddressInRange(std::istream &Stream, uintptr_t Addr) {
104104

105105
/// Returns an absolute path to a directory where the object was found.
106106
std::string OSUtil::getCurrentDSODir() {
107-
// Examine /proc/self/maps and find where ^~~this function comes from - this
108-
// is supposed to be an absolute path to libsycl.so.
107+
// Examine /proc/self/maps and find where this function (getCurrendDSODir)
108+
// comes from - this is supposed to be an absolute path to libsycl.so.
109109
//
110110
// File structure is the following:
111111
// address perms offset dev inode pathname
@@ -142,21 +142,17 @@ std::string OSUtil::getCurrentDSODir() {
142142
Stream.ignore(1);
143143

144144
// Read and ignore the following:
145-
uintptr_t Offset, DevMajor, DevMinor, Inode;
146-
Stream >> Offset;
147-
assert(Stream.peek() == ' ');
145+
// offset
146+
Stream.ignore(std::numeric_limits<std::streamsize>::max(), ' ');
148147
Stream.ignore(1);
149-
150-
Stream >> DevMajor;
151-
assert(Stream.peek() == ':' &&
152-
"Couldn't read dev field in /proc/self/maps");
148+
// dev major
149+
Stream.ignore(std::numeric_limits<std::streamsize>::max(), ':');
153150
Stream.ignore(1);
154-
Stream >> DevMinor;
155-
assert(Stream.peek() == ' ');
151+
// dev minor
152+
Stream.ignore(std::numeric_limits<std::streamsize>::max(), ' ');
156153
Stream.ignore(1);
157-
158-
Stream >> Inode;
159-
assert(Stream.peek() == ' ');
154+
// inode
155+
Stream.ignore(std::numeric_limits<std::streamsize>::max(), ' ');
160156
Stream.ignore(1);
161157

162158
// Now read the path: it is padded with whitespaces, so we skip them
@@ -175,9 +171,11 @@ std::string OSUtil::getCurrentDSODir() {
175171

176172
std::string OSUtil::getDirName(const char* Path) {
177173
std::string Tmp(Path);
178-
// dirname(3) needs a writable C string
179-
return std::string(
180-
dirname(const_cast<char*>(Tmp.c_str())));
174+
// dirname(3) needs a writable C string: a null-terminator is written where a
175+
// path should split.
176+
size_t TruncatedSize = strlen(dirname(const_cast<char*>(Tmp.c_str())));
177+
Tmp.resize(TruncatedSize);
178+
return Tmp;
181179
}
182180

183181
#elif defined(SYCL_RT_OS_WINDOWS)

0 commit comments

Comments
 (0)