Skip to content

Commit 2829628

Browse files
committed
Fix missing newline in sysfs file
When using cat command to read /sys/class/kxo/kxo/kxo_state file, the output (e.g., "1 1 0") did not include a newline, causing the terminal prompt to appear on the same line (e.g., "1 1 0user@Ubuntu:~$"). This truncation issue is diagnosed by examining kxo_state_show, which uses snprintf with a format string "%c %c %c\n". The size parameter of snprintf set to 6 included the null terminator \0 as the last character, leaving only 5 bytes for the desired output (e.g., "1 0 0\n"), thus the newline symbol \n was truncated by null terminator. This commit resolves the issue by increasing the size parameter of snprintf from 6 to 7, ensuring the output includes the newline.
1 parent efff9ee commit 2829628

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static ssize_t kxo_state_show(struct device *dev,
4848
char *buf)
4949
{
5050
read_lock(&attr_obj.lock);
51-
int ret = snprintf(buf, 6, "%c %c %c\n", attr_obj.display, attr_obj.resume,
51+
int ret = snprintf(buf, 7, "%c %c %c\n", attr_obj.display, attr_obj.resume,
5252
attr_obj.end);
5353
read_unlock(&attr_obj.lock);
5454
return ret;

0 commit comments

Comments
 (0)