@@ -88,7 +88,7 @@ OSModuleHandle OSUtil::getOSModuleHandle(const void *VirtAddr) {
88
88
}
89
89
90
90
bool procMapsAddressInRange (std::istream &Stream, uintptr_t Addr) {
91
- uintptr_t Start, End;
91
+ uintptr_t Start = 0 , End = 0 ;
92
92
Stream >> Start;
93
93
assert (!Stream.fail () && Stream.peek () == ' -' &&
94
94
" Couldn't read /proc/self/maps correctly" );
@@ -104,8 +104,8 @@ bool procMapsAddressInRange(std::istream &Stream, uintptr_t Addr) {
104
104
105
105
// / Returns an absolute path to a directory where the object was found.
106
106
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.
109
109
//
110
110
// File structure is the following:
111
111
// address perms offset dev inode pathname
@@ -142,21 +142,17 @@ std::string OSUtil::getCurrentDSODir() {
142
142
Stream.ignore (1 );
143
143
144
144
// 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 (), ' ' );
148
147
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 (), ' :' );
153
150
Stream.ignore (1 );
154
- Stream >> DevMinor;
155
- assert ( Stream.peek () == ' ' );
151
+ // dev minor
152
+ Stream.ignore (std::numeric_limits<std::streamsize>:: max (), ' ' );
156
153
Stream.ignore (1 );
157
-
158
- Stream >> Inode;
159
- assert (Stream.peek () == ' ' );
154
+ // inode
155
+ Stream.ignore (std::numeric_limits<std::streamsize>::max (), ' ' );
160
156
Stream.ignore (1 );
161
157
162
158
// Now read the path: it is padded with whitespaces, so we skip them
@@ -175,9 +171,11 @@ std::string OSUtil::getCurrentDSODir() {
175
171
176
172
std::string OSUtil::getDirName (const char * Path) {
177
173
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;
181
179
}
182
180
183
181
#elif defined(SYCL_RT_OS_WINDOWS)
0 commit comments