use size_t when we refer to memory sizes

This commit is contained in:
Kovarththanan Rajaratnam 2010-02-22 22:58:41 +01:00
parent 5c6b15ddee
commit 8f2365f24d
5 changed files with 11 additions and 10 deletions

View File

@ -56,7 +56,7 @@ int hash_fd(struct mdfour *md, int fd);
int hash_file(struct mdfour *md, const char *fname);
char *hash_result(struct mdfour *md);
void hash_result_as_bytes(struct mdfour *md, unsigned char *out);
void hash_buffer(struct mdfour *md, const char *s, int len);
void hash_buffer(struct mdfour *md, const char *s, size_t len);
void cc_log(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
void fatal(const char *format, ...) ATTR_FORMAT(printf, 1, 2);

4
hash.c
View File

@ -25,7 +25,7 @@
#include <string.h>
#include <unistd.h>
void hash_buffer(struct mdfour *md, const char *s, int len)
void hash_buffer(struct mdfour *md, const char *s, size_t len)
{
mdfour_update(md, (unsigned char *)s, len);
}
@ -51,7 +51,7 @@ void hash_int(struct mdfour *md, int x)
int hash_fd(struct mdfour *md, int fd)
{
char buf[1024];
int n;
size_t n;
while ((n = read(fd, buf, sizeof(buf))) > 0) {
hash_buffer(md, buf, n);

View File

@ -110,7 +110,7 @@ void mdfour_begin(struct mdfour *md)
}
static void mdfour_tail(const unsigned char *in, int n)
static void mdfour_tail(const unsigned char *in, size_t n)
{
unsigned char buf[128];
uint32_t M[16];
@ -137,7 +137,7 @@ static void mdfour_tail(const unsigned char *in, int n)
}
}
void mdfour_update(struct mdfour *md, const unsigned char *in, int n)
void mdfour_update(struct mdfour *md, const unsigned char *in, size_t n)
{
uint32_t M[16];
@ -149,7 +149,7 @@ void mdfour_update(struct mdfour *md, const unsigned char *in, int n)
}
if (md->tail_len) {
int len = 64 - md->tail_len;
size_t len = 64 - md->tail_len;
if (len > n) len = n;
memcpy(md->tail+md->tail_len, in, len);
md->tail_len += len;

View File

@ -22,17 +22,18 @@
#ifndef MDFOUR_H
#define MDFOUR_H
#include <stddef.h>
#include <inttypes.h>
struct mdfour {
uint32_t A, B, C, D;
uint32_t totalN;
size_t totalN;
unsigned char tail[64];
unsigned tail_len;
size_t tail_len;
};
void mdfour_begin(struct mdfour *md);
void mdfour_update(struct mdfour *md, const unsigned char *in, int n);
void mdfour_update(struct mdfour *md, const unsigned char *in, size_t n);
void mdfour_result(struct mdfour *md, unsigned char *out);
#endif

View File

@ -102,7 +102,7 @@ static void build_table(void)
static void pushchar(struct mdfour *hash, unsigned char c)
{
static unsigned char buf[64];
static int len;
static size_t len;
if (c == 0) {
if (len > 0) {