Drop mc->maxLen field

This commit is contained in:
Benny Baumann 2021-05-17 23:15:24 +02:00 committed by BenBE
parent 2824e2989a
commit 7ef58f2dcf
3 changed files with 6 additions and 5 deletions

View File

@ -425,7 +425,12 @@ void Process_makeCommandStr(Process *this) {
if (mc->cmdlineChanged || mc->commChanged || mc->exeChanged) { if (mc->cmdlineChanged || mc->commChanged || mc->exeChanged) {
free(mc->str); free(mc->str);
/* Accommodate the column text, two field separators and terminating NUL */ /* Accommodate the column text, two field separators and terminating NUL */
mc->str = xCalloc(1, mc->maxLen + 2 * SEPARATOR_LEN + 1); size_t maxLen = 2 * SEPARATOR_LEN + 1;
maxLen += this->cmdline ? strlen(this->cmdline) : strlen("(zombie)");
maxLen += this->procComm ? strlen(this->procComm) : 0;
maxLen += this->procExe ? strlen(this->procExe) : 0;
mc->str = xCalloc(1, maxLen);
} }
/* Preserve the settings used in this run */ /* Preserve the settings used in this run */

View File

@ -72,7 +72,6 @@ typedef struct ProcessCmdlineHighlight_ {
* threads and zombies */ * threads and zombies */
typedef struct ProcessMergedCommand_ { typedef struct ProcessMergedCommand_ {
char *str; /* merged Command string */ char *str; /* merged Command string */
size_t maxLen; /* maximum expected length of Command string */
size_t highlightCount; /* how many portions of cmdline to highlight */ size_t highlightCount; /* how many portions of cmdline to highlight */
ProcessCmdlineHighlight highlights[8]; /* which portions of cmdline to highlight */ ProcessCmdlineHighlight highlights[8]; /* which portions of cmdline to highlight */
bool separateComm : 1; /* whether comm is a separate field */ bool separateComm : 1; /* whether comm is a separate field */

View File

@ -1131,7 +1131,6 @@ static bool LinuxProcessList_readCmdlineFile(Process* process, openat_arg_t proc
} }
ProcessMergedCommand *mc = &process->mergedCommand; ProcessMergedCommand *mc = &process->mergedCommand;
mc->maxLen = lastChar + 1; /* accommodate cmdline */
if (!process->cmdline || !String_eq(command, process->cmdline)) { if (!process->cmdline || !String_eq(command, process->cmdline)) {
free_and_xStrdup(&process->cmdline, command); free_and_xStrdup(&process->cmdline, command);
process->cmdlineBasenameStart = tokenStart; process->cmdlineBasenameStart = tokenStart;
@ -1142,7 +1141,6 @@ static bool LinuxProcessList_readCmdlineFile(Process* process, openat_arg_t proc
/* /proc/[pid]/comm could change, so should be updated */ /* /proc/[pid]/comm could change, so should be updated */
if ((amtRead = xReadfileat(procFd, "comm", command, sizeof(command))) > 0) { if ((amtRead = xReadfileat(procFd, "comm", command, sizeof(command))) > 0) {
command[amtRead - 1] = '\0'; command[amtRead - 1] = '\0';
mc->maxLen += amtRead - 1; /* accommodate comm */
if (!process->procComm || !String_eq(command, process->procComm)) { if (!process->procComm || !String_eq(command, process->procComm)) {
free_and_xStrdup(&process->procComm, command); free_and_xStrdup(&process->procComm, command);
mc->commChanged = true; mc->commChanged = true;
@ -1165,7 +1163,6 @@ static bool LinuxProcessList_readCmdlineFile(Process* process, openat_arg_t proc
#endif #endif
if (amtRead > 0) { if (amtRead > 0) {
filename[amtRead] = 0; filename[amtRead] = 0;
mc->maxLen += amtRead; /* accommodate exe */
if (!process->procExe || if (!process->procExe ||
(!process->procExeDeleted && !String_eq(filename, process->procExe)) || (!process->procExeDeleted && !String_eq(filename, process->procExe)) ||
(process->procExeDeleted && !String_startsWith(filename, process->procExe))) { (process->procExeDeleted && !String_startsWith(filename, process->procExe))) {