@@ -139,12 +139,13 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons
139139 if (exePath )
140140 {
141141 snprintf (filePath , sizeof (filePath ), "/proc/%d/exe" , (int )pid );
142- ffStrbufEnsureFixedLengthFree ( exePath , PATH_MAX ) ;
143- ssize_t length = readlink (filePath , exePath -> chars , exePath -> allocated - 1 );
142+ char buf [ PATH_MAX ] ;
143+ ssize_t length = readlink (filePath , buf , PATH_MAX - 1 );
144144 if (length > 0 ) // doesn't contain trailing NUL
145145 {
146- exePath -> chars [length ] = '\0' ;
147- exePath -> length = (uint32_t ) length ;
146+ buf [length ] = '\0' ;
147+ ffStrbufEnsureFixedLengthFree (exePath , (uint32_t )length + 1 ); // +1 for the NUL
148+ ffStrbufAppendNS (exePath , (uint32_t )length , buf );
148149 }
149150 }
150151
@@ -242,7 +243,7 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons
242243
243244 #elif defined(__sun )
244245
245- char filePath [PATH_MAX ];
246+ char filePath [128 ];
246247 snprintf (filePath , sizeof (filePath ), "/proc/%d/psinfo" , (int ) pid );
247248 psinfo_t proc ;
248249 if (ffReadFileData (filePath , sizeof (proc ), & proc ) == sizeof (proc ))
@@ -254,12 +255,13 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons
254255 if (exePath )
255256 {
256257 snprintf (filePath , sizeof (filePath ), "/proc/%d/path/a.out" , (int ) pid );
257- ffStrbufEnsureFixedLengthFree ( exePath , PATH_MAX ) ;
258- ssize_t length = readlink (filePath , exePath -> chars , exePath -> allocated - 1 );
258+ char buf [ PATH_MAX ] ;
259+ ssize_t length = readlink (filePath , buf , PATH_MAX - 1 );
259260 if (length > 0 ) // doesn't contain trailing NUL
260261 {
261- exePath -> chars [length ] = '\0' ;
262- exePath -> length = (uint32_t ) length ;
262+ buf [length ] = '\0' ;
263+ ffStrbufEnsureFixedLengthFree (exePath , (uint32_t )length + 1 ); // +1 for the NUL
264+ ffStrbufAppendNS (exePath , (uint32_t )length , buf );
263265 }
264266 }
265267
0 commit comments