We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9300507 commit d24c95dCopy full SHA for d24c95d
include/tkey/proto.h
@@ -39,6 +39,5 @@ int parseframe(uint8_t b, struct frame_header *hdr);
39
void writebyte(uint8_t b);
40
void write(const uint8_t *buf, size_t nbytes);
41
uint8_t readbyte();
42
-void read(uint8_t *buf, size_t nbytes);
43
-
+int read(uint8_t *buf, size_t bufsize, size_t nbytes);
44
#endif
libcommon/proto.c
@@ -82,9 +82,15 @@ uint8_t readbyte()
82
}
83
84
85
-void read(uint8_t *buf, size_t nbytes)
+int read(uint8_t *buf, size_t bufsize, size_t nbytes)
86
{
87
+ if (nbytes > bufsize) {
88
+ return -1;
89
+ }
90
+
91
for (int n = 0; n < nbytes; n++) {
92
buf[n] = readbyte();
93
94
95
+ return 0;
96
0 commit comments