Skip to content

Conversation

@guybortnikov
Copy link

No description provided.

@guybortnikov guybortnikov requested a review from Jongy May 6, 2021 19:29
goto error;
}

fread_res = getline(&line, &line_len, f);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't initialize line before reading?

And why use a complicated API like getline when you just gotta read 16 bytes?

log_error("Couldn't read %s file - errno %d\n", proc_fs_path, pid);
goto error;
}
comm_len = (size_t) fread_res - 1; /* remove \n delimiter */
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handle the 0 case so you don't underflow


/* Force null termination */
if (comm_len >= buf_size) {
buf[buf_size] = '\0';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
buf[buf_size] = '\0';
buf[buf_size - 1] = '\0';

}

strncpy(buf, "UNKNOWN-COMM", buf_size);
buf[buf_size] = '\0'; /* terminate just in case because strncpy doesn't */
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

@EzraDechwong0 EzraDechwong0 Jan 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants