浏览代码

Merge pull request #162 from linD026/master

Fix the buffer length may cause a read error
Jim Huang 2 年之前
父节点
当前提交
d79fdc8559
共有 2 个文件被更改,包括 2 次插入2 次删除
  1. 1 1
      examples/chardev.c
  2. 1 1
      examples/chardev2.c

+ 1 - 1
examples/chardev.c

@@ -36,7 +36,7 @@ enum {
 /* Is device open? Used to prevent multiple access to device */
 static atomic_t already_open = ATOMIC_INIT(CDEV_NOT_USED);
 
-static char msg[BUF_LEN]; /* The msg the device will give when asked */
+static char msg[BUF_LEN + 1]; /* The msg the device will give when asked */
 
 static struct class *cls;
 

+ 1 - 1
examples/chardev2.c

@@ -28,7 +28,7 @@ enum {
 static atomic_t already_open = ATOMIC_INIT(CDEV_NOT_USED);
 
 /* The message the device will give when asked */
-static char message[BUF_LEN];
+static char message[BUF_LEN + 1];
 
 static struct class *cls;