summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2022-01-14 09:53:14 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2022-01-14 09:53:14 (GMT)
commit2dd5df343a4d942668e094deb4363e8b7a938868 (patch)
tree60e8701a1c0da2aadc5765cf6163461a2c397ed9 /generic
parentbe409f301ed5dff8685300d8f28e0e06711ee22d (diff)
parente874b759fc95fea19afd03d71388ed379872493f (diff)
downloadtcl-2dd5df343a4d942668e094deb4363e8b7a938868.zip
tcl-2dd5df343a4d942668e094deb4363e8b7a938868.tar.gz
tcl-2dd5df343a4d942668e094deb4363e8b7a938868.tar.bz2
Fix [bca10e3790]: Undefined behavior in ResultAdd(). Make functions like ResultAdd() equal in tclIOGt.c and tclIOTrans.c
Diffstat (limited to 'generic')
-rw-r--r--generic/tclIOGT.c8
-rw-r--r--generic/tclIORTrans.c30
2 files changed, 19 insertions, 19 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.
*/
diff --git a/generic/tclIORTrans.c b/generic/tclIORTrans.c
index e0c39ad..eecd412 100644
--- a/generic/tclIORTrans.c
+++ b/generic/tclIORTrans.c
@@ -85,22 +85,22 @@ static const Tcl_ChannelType tclRTransformType = {
* layers upon reading from the channel, plus the functions to manage such.
*/
-typedef struct _ResultBuffer_ {
+typedef struct {
unsigned char *buf; /* Reference to the buffer area. */
- int allocated; /* Allocated size of the buffer area. */
- int used; /* Number of bytes in the buffer,
+ size_t allocated; /* Allocated size of the buffer area. */
+ size_t used; /* Number of bytes in the buffer,
* <= allocated. */
} ResultBuffer;
#define ResultLength(r) ((r)->used)
/* static int ResultLength(ResultBuffer *r); */
-static void ResultClear(ResultBuffer *r);
-static void ResultInit(ResultBuffer *r);
-static void ResultAdd(ResultBuffer *r, unsigned char *buf,
- int toWrite);
-static int ResultCopy(ResultBuffer *r, unsigned char *buf,
- int toRead);
+static inline void ResultClear(ResultBuffer *r);
+static inline void ResultInit(ResultBuffer *r);
+static inline void ResultAdd(ResultBuffer *r, unsigned char *buf,
+ size_t toWrite);
+static inline size_t ResultCopy(ResultBuffer *r, unsigned char *buf,
+ size_t toRead);
#define RB_INCREMENT (512)
@@ -2934,7 +2934,7 @@ TimerRun(
*----------------------------------------------------------------------
*/
-static void
+static inline void
ResultInit(
ResultBuffer *rPtr) /* Reference to the structure to
* initialize. */
@@ -2959,7 +2959,7 @@ ResultInit(
*----------------------------------------------------------------------
*/
-static void
+static inline void
ResultClear(
ResultBuffer *rPtr) /* Reference to the buffer to clear out */
{
@@ -2990,11 +2990,11 @@ ResultClear(
*----------------------------------------------------------------------
*/
-static void
+static inline void
ResultAdd(
ResultBuffer *rPtr, /* The buffer to extend */
unsigned char *buf, /* The buffer to read from */
- int toWrite) /* The number of bytes in 'buf' */
+ size_t toWrite) /* The number of bytes in 'buf' */
{
if ((rPtr->used + toWrite + 1) > rPtr->allocated) {
/*
@@ -3038,11 +3038,11 @@ ResultAdd(
*----------------------------------------------------------------------
*/
-static int
+static inline size_t
ResultCopy(
ResultBuffer *rPtr, /* The buffer to read from */
unsigned char *buf, /* The buffer to copy into */
- int toRead) /* Number of requested bytes */
+ size_t toRead) /* Number of requested bytes */
{
int copied;