@@ -64,28 +64,25 @@ void Process_fillStarttimeBuffer(Process* this) {
6464 */
6565#define TASK_COMM_LEN 16
6666
67- static bool findCommInCmdline (const char * comm , const char * cmdline , int cmdlineBasenameStart , int * pCommStart , int * pCommLen ) {
67+ static bool findCommInCmdline (const char * comm , const char * cmdline , size_t cmdlineBasenameStart , size_t * pCommStart , size_t * pCommLen ) {
6868 /* Try to find procComm in tokenized cmdline - this might in rare cases
6969 * mis-identify a string or fail, if comm or cmdline had been unsuitably
7070 * modified by the process */
7171 const char * tokenBase ;
7272 size_t tokenLen ;
7373 const size_t commLen = strlen (comm );
7474
75- if (cmdlineBasenameStart < 0 )
76- return false;
77-
7875 for (const char * token = cmdline + cmdlineBasenameStart ; * token ;) {
7976 for (tokenBase = token ; * token && * token != '\n' ; ++ token ) {
8077 if (* token == '/' ) {
8178 tokenBase = token + 1 ;
8279 }
8380 }
84- tokenLen = token - tokenBase ;
81+ tokenLen = ( size_t )( token - tokenBase ) ;
8582
8683 if ((tokenLen == commLen || (tokenLen > commLen && commLen == (TASK_COMM_LEN - 1 ))) &&
8784 strncmp (tokenBase , comm , commLen ) == 0 ) {
88- * pCommStart = tokenBase - cmdline ;
85+ * pCommStart = ( size_t )( tokenBase - cmdline ) ;
8986 * pCommLen = tokenLen ;
9087 return true;
9188 }
@@ -99,10 +96,10 @@ static bool findCommInCmdline(const char* comm, const char* cmdline, int cmdline
9996 return false;
10097}
10198
102- static int matchCmdlinePrefixWithExeSuffix (const char * cmdline , int * cmdlineBasenameStart , const char * exe , int exeBaseOffset , int exeBaseLen ) {
99+ static size_t matchCmdlinePrefixWithExeSuffix (const char * cmdline , size_t * cmdlineBasenameStart , const char * exe , size_t exeBaseOffset , size_t exeBaseLen ) {
103100 /* cmdline prefix is an absolute path: it must match whole exe. */
104101 if (cmdline [0 ] == '/' ) {
105- int matchLen = exeBaseLen + exeBaseOffset ;
102+ size_t matchLen = exeBaseLen + exeBaseOffset ;
106103 if (strncmp (cmdline , exe , matchLen ) == 0 ) {
107104 char delim = cmdline [matchLen ];
108105 if (delim == 0 || delim == '\n' || delim == ' ' ) {
@@ -124,18 +121,18 @@ static int matchCmdlinePrefixWithExeSuffix(const char* cmdline, int* cmdlineBase
124121 *
125122 * So if needed, we adjust cmdlineBaseOffset to the previous (if any)
126123 * component of the cmdline relative path, and retry the procedure. */
127- int cmdlineBaseOffset = * cmdlineBasenameStart ;
124+ size_t cmdlineBaseOffset = * cmdlineBasenameStart ;
128125 bool delimFound = true; /* if valid basename delimiter found */
129126 do {
130127 /* match basename */
131- int matchLen = exeBaseLen + cmdlineBaseOffset ;
128+ size_t matchLen = exeBaseLen + cmdlineBaseOffset ;
132129 if (cmdlineBaseOffset < exeBaseOffset &&
133130 strncmp (cmdline + cmdlineBaseOffset , exe + exeBaseOffset , exeBaseLen ) == 0 ) {
134131 char delim = cmdline [matchLen ];
135132 if (delim == 0 || delim == '\n' || delim == ' ' ) {
136133 /* reverse match the cmdline prefix and exe suffix */
137- int i = cmdlineBaseOffset ;
138- int j = exeBaseOffset ;
134+ size_t i = cmdlineBaseOffset ;
135+ size_t j = exeBaseOffset ;
139136 while (i >= 1 && j >= 1 && cmdline [i - 1 ] == exe [j - 1 ]) {
140137 -- i , -- j ;
141138 }
@@ -151,6 +148,9 @@ static int matchCmdlinePrefixWithExeSuffix(const char* cmdline, int* cmdlineBase
151148 /* Try to find the previous potential cmdlineBaseOffset - it would be
152149 * preceded by '/' or nothing, and delimited by ' ' or '\n' */
153150 delimFound = false;
151+ if (cmdlineBaseOffset <= 2 ) {
152+ return 0 ;
153+ }
154154 for (cmdlineBaseOffset -= 2 ; cmdlineBaseOffset > 0 ; -- cmdlineBaseOffset ) {
155155 if (delimFound ) {
156156 if (cmdline [cmdlineBaseOffset - 1 ] == '/' ) {
@@ -311,8 +311,8 @@ void Process_makeCommandStr(Process* this, const Settings* settings) {
311311 char * strStart = mc -> str ;
312312 char * str = strStart ;
313313
314- int cmdlineBasenameStart = this -> cmdlineBasenameStart ;
315- int cmdlineBasenameLen = 0 ;
314+ size_t cmdlineBasenameStart = this -> cmdlineBasenameStart ;
315+ size_t cmdlineBasenameLen = 0 ;
316316 if (this -> cmdlineBasenameEnd > this -> cmdlineBasenameStart )
317317 cmdlineBasenameLen = this -> cmdlineBasenameEnd - this -> cmdlineBasenameStart ;
318318
@@ -322,20 +322,18 @@ void Process_makeCommandStr(Process* this, const Settings* settings) {
322322 cmdline = "(zombie)" ;
323323 }
324324
325- assert (cmdlineBasenameStart >= 0 );
326- assert (cmdlineBasenameStart <= (int )strlen (cmdline ));
325+ assert (cmdlineBasenameStart <= strlen (cmdline ));
327326
328- int exeLen = 0 ;
329- int exeBasenameOffset = 0 ;
330- int exeBasenameLen = 0 ;
331- int matchLen = 0 ;
327+ size_t exeLen = 0 ;
328+ size_t exeBasenameOffset = 0 ;
329+ size_t exeBasenameLen = 0 ;
330+ size_t matchLen = 0 ;
332331 if (procExe ) {
333332 exeLen = strlen (procExe );
334333 exeBasenameOffset = this -> procExeBasenameOffset ;
335334 exeBasenameLen = exeLen - exeBasenameOffset ;
336335
337- assert (exeBasenameOffset >= 0 );
338- assert (exeBasenameOffset <= (int )strlen (procExe ));
336+ assert (exeBasenameOffset <= strlen (procExe ));
339337
340338 if (this -> cmdline ) {
341339 matchLen = matchCmdlinePrefixWithExeSuffix (this -> cmdline , & cmdlineBasenameStart , procExe , exeBasenameOffset , exeBasenameLen );
@@ -375,7 +373,7 @@ void Process_makeCommandStr(Process* this, const Settings* settings) {
375373 return ;
376374 }
377375
378- int commLen = 0 ;
376+ size_t commLen = 0 ;
379377
380378 bool haveCommInExe = false;
381379 if (procExe && procComm && (!Process_isUserlandThread (this ) || showThreadNames )) {
@@ -386,7 +384,7 @@ void Process_makeCommandStr(Process* this, const Settings* settings) {
386384 }
387385
388386 bool haveCommInCmdline = false;
389- int commStart = 0 ;
387+ size_t commStart = 0 ;
390388
391389 if (!haveCommInExe && this -> cmdline && procComm && searchCommInCmdline && (!Process_isUserlandThread (this ) || showThreadNames )) {
392390 haveCommInCmdline = findCommInCmdline (procComm , cmdline , cmdlineBasenameStart , & commStart , & commLen );
@@ -470,20 +468,20 @@ void Process_writeCommand(const Process* this, int attr, int baseAttr, RichStrin
470468 const ProcessMergedCommand * mc = & this -> mergedCommand ;
471469 const char * mergedCommand = mc -> str ;
472470
473- int strStart = RichString_size (str );
471+ size_t strStart = RichString_size (str );
474472
475473 const Settings * settings = this -> super .host -> settings ;
476474 const bool highlightBaseName = settings -> highlightBaseName ;
477475 const bool highlightSeparator = true;
478476 const bool highlightDeleted = settings -> highlightDeletedExe ;
479477
480478 if (!mergedCommand ) {
481- int len = 0 ;
479+ size_t len = 0 ;
482480 const char * cmdline = this -> cmdline ;
483481
484482 if (highlightBaseName || !settings -> showProgramPath ) {
485- int basename = 0 ;
486- for (int i = 0 ; i < this -> cmdlineBasenameEnd ; i ++ ) {
483+ size_t basename = 0 ;
484+ for (size_t i = 0 ; i < this -> cmdlineBasenameEnd ; i ++ ) {
487485 if (cmdline [i ] == '/' ) {
488486 basename = i + 1 ;
489487 } else if (cmdline [i ] == ':' ) {
@@ -874,7 +872,7 @@ bool Process_rowMatchesFilter(const Row* super, const Table* table) {
874872void Process_init (Process * this , const Machine * host ) {
875873 Row_init (& this -> super , host );
876874
877- this -> cmdlineBasenameEnd = -1 ;
875+ this -> cmdlineBasenameEnd = 0 ;
878876 this -> st_uid = (uid_t )- 1 ;
879877}
880878
@@ -1026,12 +1024,12 @@ void Process_updateComm(Process* this, const char* comm) {
10261024 this -> mergedCommand .lastUpdate = 0 ;
10271025}
10281026
1029- static int skipPotentialPath (const char * cmdline , int end ) {
1027+ static size_t skipPotentialPath (const char * cmdline , size_t end ) {
10301028 if (cmdline [0 ] != '/' )
10311029 return 0 ;
10321030
1033- int slash = 0 ;
1034- for (int i = 1 ; i < end ; i ++ ) {
1031+ size_t slash = 0 ;
1032+ for (size_t i = 1 ; i < end ; i ++ ) {
10351033 if (cmdline [i ] == '/' && cmdline [i + 1 ] != '\0' ) {
10361034 slash = i + 1 ;
10371035 continue ;
@@ -1047,11 +1045,10 @@ static int skipPotentialPath(const char* cmdline, int end) {
10471045 return slash ;
10481046}
10491047
1050- void Process_updateCmdline (Process * this , const char * cmdline , int basenameStart , int basenameEnd ) {
1051- assert (basenameStart >= 0 );
1052- assert ((cmdline && basenameStart < (int )strlen (cmdline )) || (!cmdline && basenameStart == 0 ));
1048+ void Process_updateCmdline (Process * this , const char * cmdline , size_t basenameStart , size_t basenameEnd ) {
1049+ assert ((cmdline && basenameStart < strlen (cmdline )) || (!cmdline && basenameStart == 0 ));
10531050 assert ((basenameEnd > basenameStart ) || (basenameEnd == 0 && basenameStart == 0 ));
1054- assert ((cmdline && basenameEnd <= ( int ) strlen (cmdline )) || (!cmdline && basenameEnd == 0 ));
1051+ assert ((cmdline && basenameEnd <= strlen (cmdline )) || (!cmdline && basenameEnd == 0 ));
10551052
10561053 if (!this -> cmdline && !cmdline )
10571054 return ;
@@ -1084,7 +1081,7 @@ void Process_updateExe(Process* this, const char* exe) {
10841081 if (exe ) {
10851082 this -> procExe = xStrdup (exe );
10861083 const char * lastSlash = strrchr (exe , '/' );
1087- this -> procExeBasenameOffset = (lastSlash && * (lastSlash + 1 ) != '\0' && lastSlash != exe ) ? (lastSlash - exe + 1 ) : 0 ;
1084+ this -> procExeBasenameOffset = (lastSlash && * (lastSlash + 1 ) != '\0' && lastSlash != exe ) ? (size_t )( lastSlash - exe + 1 ) : 0 ;
10881085 } else {
10891086 this -> procExe = NULL ;
10901087 this -> procExeBasenameOffset = 0 ;
0 commit comments