summaryrefslogtreecommitdiffstats
path: root/generic/tclIOGT.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2022-01-13 11:12:40 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2022-01-13 11:12:40 (GMT)
commite874b759fc95fea19afd03d71388ed379872493f (patch)
tree7a26fe8188bc37859ffd57693c700aea18940e6b /generic/tclIOGT.c
parent32ab46ae406d7fd3db0516dd45f38c7c48c6bd3c (diff)
downloadtcl-e874b759fc95fea19afd03d71388ed379872493f.zip
tcl-e874b759fc95fea19afd03d71388ed379872493f.tar.gz
tcl-e874b759fc95fea19afd03d71388ed379872493f.tar.bz2
Suggested fix for [bca10e3790]: Undefined behavior in ResultAdd(). Make functions like ResultAdd() equal in tclIOGt.c and tclIOTrans.c
Diffstat (limited to 'generic/tclIOGT.c')
-rw-r--r--generic/tclIOGT.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/generic/tclIOGT.c b/generic/tclIOGT.c
index dadcb53..6b1c341 100644
--- a/generic/tclIOGT.c
+++ b/generic/tclIOGT.c
@@ -108,7 +108,7 @@ typedef struct ResultBuffer ResultBuffer;
static inline void ResultClear(ResultBuffer *r);
static inline void ResultInit(ResultBuffer *r);
static inline int ResultEmpty(ResultBuffer *r);
-static inline int ResultCopy(ResultBuffer *r, unsigned char *buf,
+static inline size_t ResultCopy(ResultBuffer *r, unsigned char *buf,
size_t toRead);
static inline void ResultAdd(ResultBuffer *r, unsigned char *buf,
size_t toWrite);
@@ -1361,13 +1361,13 @@ ResultEmpty(
*----------------------------------------------------------------------
*/
-static inline int
+static inline size_t
ResultCopy(
ResultBuffer *r, /* The buffer to read from. */
unsigned char *buf, /* The buffer to copy into. */
size_t toRead) /* Number of requested bytes. */
{
- if (r->used == 0) {
+ if (ResultEmpty(r)) {
/*
* Nothing to copy in the case of an empty buffer.
*/
@@ -1424,7 +1424,7 @@ ResultAdd(
unsigned char *buf, /* The buffer to read from. */
size_t toWrite) /* The number of bytes in 'buf'. */
{
- if (r->used + toWrite > r->allocated) {
+ if ((r->used + toWrite + 1) > r->allocated) {
/*
* Extension of the internal buffer is required.
*/