@@ -64,28 +64,25 @@ void Process_fillStarttimeBuffer(Process* this) {
64
64
*/
65
65
#define TASK_COMM_LEN 16
66
66
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 ) {
68
68
/* Try to find procComm in tokenized cmdline - this might in rare cases
69
69
* mis-identify a string or fail, if comm or cmdline had been unsuitably
70
70
* modified by the process */
71
71
const char * tokenBase ;
72
72
size_t tokenLen ;
73
73
const size_t commLen = strlen (comm );
74
74
75
- if (cmdlineBasenameStart < 0 )
76
- return false;
77
-
78
75
for (const char * token = cmdline + cmdlineBasenameStart ; * token ;) {
79
76
for (tokenBase = token ; * token && * token != '\n' ; ++ token ) {
80
77
if (* token == '/' ) {
81
78
tokenBase = token + 1 ;
82
79
}
83
80
}
84
- tokenLen = token - tokenBase ;
81
+ tokenLen = ( size_t )( token - tokenBase ) ;
85
82
86
83
if ((tokenLen == commLen || (tokenLen > commLen && commLen == (TASK_COMM_LEN - 1 ))) &&
87
84
strncmp (tokenBase , comm , commLen ) == 0 ) {
88
- * pCommStart = tokenBase - cmdline ;
85
+ * pCommStart = ( size_t )( tokenBase - cmdline ) ;
89
86
* pCommLen = tokenLen ;
90
87
return true;
91
88
}
@@ -99,10 +96,10 @@ static bool findCommInCmdline(const char* comm, const char* cmdline, int cmdline
99
96
return false;
100
97
}
101
98
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 ) {
103
100
/* cmdline prefix is an absolute path: it must match whole exe. */
104
101
if (cmdline [0 ] == '/' ) {
105
- int matchLen = exeBaseLen + exeBaseOffset ;
102
+ size_t matchLen = exeBaseLen + exeBaseOffset ;
106
103
if (strncmp (cmdline , exe , matchLen ) == 0 ) {
107
104
char delim = cmdline [matchLen ];
108
105
if (delim == 0 || delim == '\n' || delim == ' ' ) {
@@ -124,18 +121,18 @@ static int matchCmdlinePrefixWithExeSuffix(const char* cmdline, int* cmdlineBase
124
121
*
125
122
* So if needed, we adjust cmdlineBaseOffset to the previous (if any)
126
123
* component of the cmdline relative path, and retry the procedure. */
127
- int cmdlineBaseOffset = * cmdlineBasenameStart ;
124
+ size_t cmdlineBaseOffset = * cmdlineBasenameStart ;
128
125
bool delimFound = true; /* if valid basename delimiter found */
129
126
do {
130
127
/* match basename */
131
- int matchLen = exeBaseLen + cmdlineBaseOffset ;
128
+ size_t matchLen = exeBaseLen + cmdlineBaseOffset ;
132
129
if (cmdlineBaseOffset < exeBaseOffset &&
133
130
strncmp (cmdline + cmdlineBaseOffset , exe + exeBaseOffset , exeBaseLen ) == 0 ) {
134
131
char delim = cmdline [matchLen ];
135
132
if (delim == 0 || delim == '\n' || delim == ' ' ) {
136
133
/* 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 ;
139
136
while (i >= 1 && j >= 1 && cmdline [i - 1 ] == exe [j - 1 ]) {
140
137
-- i , -- j ;
141
138
}
@@ -151,6 +148,9 @@ static int matchCmdlinePrefixWithExeSuffix(const char* cmdline, int* cmdlineBase
151
148
/* Try to find the previous potential cmdlineBaseOffset - it would be
152
149
* preceded by '/' or nothing, and delimited by ' ' or '\n' */
153
150
delimFound = false;
151
+ if (cmdlineBaseOffset <= 2 ) {
152
+ return 0 ;
153
+ }
154
154
for (cmdlineBaseOffset -= 2 ; cmdlineBaseOffset > 0 ; -- cmdlineBaseOffset ) {
155
155
if (delimFound ) {
156
156
if (cmdline [cmdlineBaseOffset - 1 ] == '/' ) {
@@ -311,8 +311,8 @@ void Process_makeCommandStr(Process* this, const Settings* settings) {
311
311
char * strStart = mc -> str ;
312
312
char * str = strStart ;
313
313
314
- int cmdlineBasenameStart = this -> cmdlineBasenameStart ;
315
- int cmdlineBasenameLen = 0 ;
314
+ size_t cmdlineBasenameStart = this -> cmdlineBasenameStart ;
315
+ size_t cmdlineBasenameLen = 0 ;
316
316
if (this -> cmdlineBasenameEnd > this -> cmdlineBasenameStart )
317
317
cmdlineBasenameLen = this -> cmdlineBasenameEnd - this -> cmdlineBasenameStart ;
318
318
@@ -322,20 +322,18 @@ void Process_makeCommandStr(Process* this, const Settings* settings) {
322
322
cmdline = "(zombie)" ;
323
323
}
324
324
325
- assert (cmdlineBasenameStart >= 0 );
326
- assert (cmdlineBasenameStart <= (int )strlen (cmdline ));
325
+ assert (cmdlineBasenameStart <= strlen (cmdline ));
327
326
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 ;
332
331
if (procExe ) {
333
332
exeLen = strlen (procExe );
334
333
exeBasenameOffset = this -> procExeBasenameOffset ;
335
334
exeBasenameLen = exeLen - exeBasenameOffset ;
336
335
337
- assert (exeBasenameOffset >= 0 );
338
- assert (exeBasenameOffset <= (int )strlen (procExe ));
336
+ assert (exeBasenameOffset <= strlen (procExe ));
339
337
340
338
if (this -> cmdline ) {
341
339
matchLen = matchCmdlinePrefixWithExeSuffix (this -> cmdline , & cmdlineBasenameStart , procExe , exeBasenameOffset , exeBasenameLen );
@@ -375,7 +373,7 @@ void Process_makeCommandStr(Process* this, const Settings* settings) {
375
373
return ;
376
374
}
377
375
378
- int commLen = 0 ;
376
+ size_t commLen = 0 ;
379
377
380
378
bool haveCommInExe = false;
381
379
if (procExe && procComm && (!Process_isUserlandThread (this ) || showThreadNames )) {
@@ -386,7 +384,7 @@ void Process_makeCommandStr(Process* this, const Settings* settings) {
386
384
}
387
385
388
386
bool haveCommInCmdline = false;
389
- int commStart = 0 ;
387
+ size_t commStart = 0 ;
390
388
391
389
if (!haveCommInExe && this -> cmdline && procComm && searchCommInCmdline && (!Process_isUserlandThread (this ) || showThreadNames )) {
392
390
haveCommInCmdline = findCommInCmdline (procComm , cmdline , cmdlineBasenameStart , & commStart , & commLen );
@@ -470,20 +468,20 @@ void Process_writeCommand(const Process* this, int attr, int baseAttr, RichStrin
470
468
const ProcessMergedCommand * mc = & this -> mergedCommand ;
471
469
const char * mergedCommand = mc -> str ;
472
470
473
- int strStart = RichString_size (str );
471
+ size_t strStart = RichString_size (str );
474
472
475
473
const Settings * settings = this -> super .host -> settings ;
476
474
const bool highlightBaseName = settings -> highlightBaseName ;
477
475
const bool highlightSeparator = true;
478
476
const bool highlightDeleted = settings -> highlightDeletedExe ;
479
477
480
478
if (!mergedCommand ) {
481
- int len = 0 ;
479
+ size_t len = 0 ;
482
480
const char * cmdline = this -> cmdline ;
483
481
484
482
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 ++ ) {
487
485
if (cmdline [i ] == '/' ) {
488
486
basename = i + 1 ;
489
487
} else if (cmdline [i ] == ':' ) {
@@ -875,7 +873,7 @@ bool Process_rowMatchesFilter(const Row* super, const Table* table) {
875
873
void Process_init (Process * this , const Machine * host ) {
876
874
Row_init (& this -> super , host );
877
875
878
- this -> cmdlineBasenameEnd = -1 ;
876
+ this -> cmdlineBasenameEnd = 0 ;
879
877
this -> st_uid = (uid_t )- 1 ;
880
878
}
881
879
@@ -1027,12 +1025,12 @@ void Process_updateComm(Process* this, const char* comm) {
1027
1025
this -> mergedCommand .lastUpdate = 0 ;
1028
1026
}
1029
1027
1030
- static int skipPotentialPath (const char * cmdline , int end ) {
1028
+ static size_t skipPotentialPath (const char * cmdline , size_t end ) {
1031
1029
if (cmdline [0 ] != '/' )
1032
1030
return 0 ;
1033
1031
1034
- int slash = 0 ;
1035
- for (int i = 1 ; i < end ; i ++ ) {
1032
+ size_t slash = 0 ;
1033
+ for (size_t i = 1 ; i < end ; i ++ ) {
1036
1034
if (cmdline [i ] == '/' && cmdline [i + 1 ] != '\0' ) {
1037
1035
slash = i + 1 ;
1038
1036
continue ;
@@ -1048,11 +1046,10 @@ static int skipPotentialPath(const char* cmdline, int end) {
1048
1046
return slash ;
1049
1047
}
1050
1048
1051
- void Process_updateCmdline (Process * this , const char * cmdline , int basenameStart , int basenameEnd ) {
1052
- assert (basenameStart >= 0 );
1053
- assert ((cmdline && basenameStart < (int )strlen (cmdline )) || (!cmdline && basenameStart == 0 ));
1049
+ void Process_updateCmdline (Process * this , const char * cmdline , size_t basenameStart , size_t basenameEnd ) {
1050
+ assert ((cmdline && basenameStart < strlen (cmdline )) || (!cmdline && basenameStart == 0 ));
1054
1051
assert ((basenameEnd > basenameStart ) || (basenameEnd == 0 && basenameStart == 0 ));
1055
- assert ((cmdline && basenameEnd <= ( int ) strlen (cmdline )) || (!cmdline && basenameEnd == 0 ));
1052
+ assert ((cmdline && basenameEnd <= strlen (cmdline )) || (!cmdline && basenameEnd == 0 ));
1056
1053
1057
1054
if (!this -> cmdline && !cmdline )
1058
1055
return ;
@@ -1085,7 +1082,7 @@ void Process_updateExe(Process* this, const char* exe) {
1085
1082
if (exe ) {
1086
1083
this -> procExe = xStrdup (exe );
1087
1084
const char * lastSlash = strrchr (exe , '/' );
1088
- this -> procExeBasenameOffset = (lastSlash && * (lastSlash + 1 ) != '\0' && lastSlash != exe ) ? (lastSlash - exe + 1 ) : 0 ;
1085
+ this -> procExeBasenameOffset = (lastSlash && * (lastSlash + 1 ) != '\0' && lastSlash != exe ) ? (size_t )( lastSlash - exe + 1 ) : 0 ;
1089
1086
} else {
1090
1087
this -> procExe = NULL ;
1091
1088
this -> procExeBasenameOffset = 0 ;
0 commit comments