Make sizes to be of type size_t and correct function arguments that
should be Byte (as the numerous casts to Byte in the function calls show).
This commit is contained in:
parent
6a0737aef1
commit
b6899024a6
@ -93,7 +93,7 @@ __FBSDID("$FreeBSD$");
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
void
|
||||
Buf_OvAddByte(Buffer bp, int byte)
|
||||
Buf_OvAddByte(Buffer bp, Byte byte)
|
||||
{
|
||||
|
||||
bp->left = 0;
|
||||
@ -122,7 +122,7 @@ Buf_OvAddByte(Buffer bp, int byte)
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
void
|
||||
Buf_AddBytes(Buffer bp, int numBytes, const Byte *bytesPtr)
|
||||
Buf_AddBytes(Buffer bp, size_t numBytes, const Byte *bytesPtr)
|
||||
{
|
||||
|
||||
BufExpand(bp, numBytes);
|
||||
@ -151,7 +151,7 @@ Buf_AddBytes(Buffer bp, int numBytes, const Byte *bytesPtr)
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
void
|
||||
Buf_UngetByte(Buffer bp, int byte)
|
||||
Buf_UngetByte(Buffer bp, Byte byte)
|
||||
{
|
||||
|
||||
if (bp->outPtr != bp->buffer) {
|
||||
@ -171,7 +171,7 @@ Buf_UngetByte(Buffer bp, int byte)
|
||||
* usually push back many bytes when they're doing it a byte at
|
||||
* a time...
|
||||
*/
|
||||
int numBytes = bp->inPtr - bp->outPtr;
|
||||
size_t numBytes = bp->inPtr - bp->outPtr;
|
||||
Byte *newBuf;
|
||||
|
||||
newBuf = emalloc(bp->size + BUF_UNGET_INC);
|
||||
@ -201,18 +201,18 @@ Buf_UngetByte(Buffer bp, int byte)
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
void
|
||||
Buf_UngetBytes(Buffer bp, int numBytes, Byte *bytesPtr)
|
||||
Buf_UngetBytes(Buffer bp, size_t numBytes, Byte *bytesPtr)
|
||||
{
|
||||
|
||||
if (bp->outPtr - bp->buffer >= numBytes) {
|
||||
if ((size_t)(bp->outPtr - bp->buffer) >= numBytes) {
|
||||
bp->outPtr -= numBytes;
|
||||
memcpy(bp->outPtr, bytesPtr, numBytes);
|
||||
} else if (bp->outPtr == bp->inPtr) {
|
||||
Buf_AddBytes(bp, numBytes, bytesPtr);
|
||||
} else {
|
||||
int curNumBytes = bp->inPtr - bp->outPtr;
|
||||
size_t curNumBytes = bp->inPtr - bp->outPtr;
|
||||
Byte *newBuf;
|
||||
int newBytes = max(numBytes, BUF_UNGET_INC);
|
||||
size_t newBytes = max(numBytes, BUF_UNGET_INC);
|
||||
|
||||
newBuf = emalloc(bp->size + newBytes);
|
||||
memcpy(newBuf + newBytes, bp->outPtr, curNumBytes + 1);
|
||||
@ -274,10 +274,10 @@ Buf_GetByte(Buffer bp)
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
int
|
||||
Buf_GetBytes(Buffer bp, int numBytes, Byte *bytesPtr)
|
||||
Buf_GetBytes(Buffer bp, size_t numBytes, Byte *bytesPtr)
|
||||
{
|
||||
|
||||
if (bp->inPtr - bp->outPtr < numBytes)
|
||||
if ((size_t)(bp->inPtr - bp->outPtr) < numBytes)
|
||||
numBytes = bp->inPtr - bp->outPtr;
|
||||
|
||||
memcpy(bytesPtr, bp->outPtr, numBytes);
|
||||
@ -305,7 +305,7 @@ Buf_GetBytes(Buffer bp, int numBytes, Byte *bytesPtr)
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
Byte *
|
||||
Buf_GetAll(Buffer bp, int *numBytesPtr)
|
||||
Buf_GetAll(Buffer bp, size_t *numBytesPtr)
|
||||
{
|
||||
|
||||
if (numBytesPtr != NULL)
|
||||
@ -328,10 +328,10 @@ Buf_GetAll(Buffer bp, int *numBytesPtr)
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
void
|
||||
Buf_Discard(Buffer bp, int numBytes)
|
||||
Buf_Discard(Buffer bp, size_t numBytes)
|
||||
{
|
||||
|
||||
if (bp->inPtr - bp->outPtr <= numBytes) {
|
||||
if ((size_t)(bp->inPtr - bp->outPtr) <= numBytes) {
|
||||
bp->inPtr = bp->outPtr = bp->buffer;
|
||||
bp->left = bp->size;
|
||||
*bp->inPtr = 0;
|
||||
@ -353,7 +353,7 @@ Buf_Discard(Buffer bp, int numBytes)
|
||||
*
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
int
|
||||
size_t
|
||||
Buf_Size(Buffer buf)
|
||||
{
|
||||
|
||||
@ -376,7 +376,7 @@ Buf_Size(Buffer buf)
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
Buffer
|
||||
Buf_Init(int size)
|
||||
Buf_Init(size_t size)
|
||||
{
|
||||
Buffer bp; /* New Buffer */
|
||||
|
||||
@ -430,7 +430,7 @@ Buf_Destroy(Buffer buf, Boolean freeData)
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
void
|
||||
Buf_ReplaceLastByte(Buffer buf, int byte)
|
||||
Buf_ReplaceLastByte(Buffer buf, Byte byte)
|
||||
{
|
||||
if (buf->inPtr == buf->outPtr)
|
||||
Buf_AddByte(buf, byte);
|
||||
|
@ -53,11 +53,11 @@
|
||||
typedef char Byte;
|
||||
|
||||
typedef struct Buffer {
|
||||
int size; /* Current size of the buffer */
|
||||
int left; /* Space left (== size - (inPtr - buffer)) */
|
||||
Byte *buffer; /* The buffer itself */
|
||||
Byte *inPtr; /* Place to write to */
|
||||
Byte *outPtr; /* Place to read from */
|
||||
size_t size; /* Current size of the buffer */
|
||||
size_t left; /* Space left (== size - (inPtr - buffer)) */
|
||||
Byte *buffer; /* The buffer itself */
|
||||
Byte *inPtr; /* Place to write to */
|
||||
Byte *outPtr; /* Place to read from */
|
||||
} *Buffer;
|
||||
|
||||
/* Buf_AddByte adds a single byte to a buffer. */
|
||||
@ -67,17 +67,17 @@ typedef struct Buffer {
|
||||
|
||||
#define BUF_ERROR 256
|
||||
|
||||
void Buf_OvAddByte(Buffer, int);
|
||||
void Buf_AddBytes(Buffer, int, const Byte *);
|
||||
void Buf_UngetByte(Buffer, int);
|
||||
void Buf_UngetBytes(Buffer, int, Byte *);
|
||||
void Buf_OvAddByte(Buffer, Byte);
|
||||
void Buf_AddBytes(Buffer, size_t, const Byte *);
|
||||
void Buf_UngetByte(Buffer, Byte);
|
||||
void Buf_UngetBytes(Buffer, size_t, Byte *);
|
||||
int Buf_GetByte(Buffer);
|
||||
int Buf_GetBytes(Buffer, int, Byte *);
|
||||
Byte *Buf_GetAll(Buffer, int *);
|
||||
void Buf_Discard(Buffer, int);
|
||||
int Buf_Size(Buffer);
|
||||
Buffer Buf_Init(int);
|
||||
int Buf_GetBytes(Buffer, size_t, Byte *);
|
||||
Byte *Buf_GetAll(Buffer, size_t *);
|
||||
void Buf_Discard(Buffer, size_t);
|
||||
size_t Buf_Size(Buffer);
|
||||
Buffer Buf_Init(size_t);
|
||||
void Buf_Destroy(Buffer, Boolean);
|
||||
void Buf_ReplaceLastByte(Buffer, int);
|
||||
void Buf_ReplaceLastByte(Buffer, Byte);
|
||||
|
||||
#endif /* _BUF_H */
|
||||
|
@ -408,7 +408,7 @@ VarSubstitute(const char *word, Boolean addSpace, Buffer buf, void *patternp)
|
||||
* buffer.
|
||||
*/
|
||||
Boolean done;
|
||||
int origSize;
|
||||
size_t origSize;
|
||||
|
||||
done = FALSE;
|
||||
origSize = Buf_Size(buf);
|
||||
|
Loading…
x
Reference in New Issue
Block a user