Skip to content

Commit

Permalink
more PVS-Studio suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Nov 16, 2012
1 parent 22a4264 commit 19389d2
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 36 deletions.
10 changes: 5 additions & 5 deletions src/mars.c
Expand Up @@ -40,9 +40,9 @@ long __cdecl __ehfilter(LPEXCEPTION_POINTERS ep);
#endif


int response_expand(int *pargc, char ***pargv);
int response_expand(size_t *pargc, char ***pargv);
void browse(const char *url);
void getenv_setargv(const char *envvar, int *pargc, char** *pargv);
void getenv_setargv(const char *envvar, size_t *pargc, char** *pargv);

void obj_start(char *srcfile);
void obj_end(Library *library, File *objfile);
Expand Down Expand Up @@ -385,7 +385,7 @@ extern "C"
}
#endif

int main(int argc, char *argv[])
int main(size_t argc, char *argv[])
{
mem.init(); // initialize storage allocator
mem.setStackBottom(&argv);
Expand Down Expand Up @@ -1493,7 +1493,7 @@ int main(int argc, char *argv[])
* The string is separated into arguments, processing \ and ".
*/

void getenv_setargv(const char *envvar, int *pargc, char** *pargv)
void getenv_setargv(const char *envvar, size_t *pargc, char** *pargv)
{
char *p;

Expand All @@ -1507,7 +1507,7 @@ void getenv_setargv(const char *envvar, int *pargc, char** *pargv)

env = mem.strdup(env); // create our own writable copy

int argc = *pargc;
size_t argc = *pargc;
Strings *argv = new Strings();
argv->setDim(argc);

Expand Down
26 changes: 12 additions & 14 deletions src/root/array.c
Expand Up @@ -59,16 +59,15 @@ Array::~Array()
}

void Array::mark()
{ unsigned u;

{
mem.mark(data);
for (u = 0; u < dim; u++)
for (size_t u = 0; u < dim; u++)
mem.mark(data[u]); // BUG: what if arrays of Object's?
}

void Array::reserve(unsigned nentries)
void Array::reserve(size_t nentries)
{
//printf("Array::reserve: dim = %d, allocdim = %d, nentries = %d\n", dim, allocdim, nentries);
//printf("Array::reserve: dim = %d, allocdim = %d, nentries = %d\n", (int)dim, (int)allocdim, (int)nentries);
if (allocdim - dim < nentries)
{
if (allocdim == 0)
Expand All @@ -95,7 +94,7 @@ void Array::reserve(unsigned nentries)
}
}

void Array::setDim(unsigned newdim)
void Array::setDim(size_t newdim)
{
if (dim < newdim)
{
Expand Down Expand Up @@ -141,7 +140,7 @@ void Array::shift(void *ptr)
dim++;
}

void Array::insert(unsigned index, void *ptr)
void Array::insert(size_t index, void *ptr)
{
reserve(1);
memmove(data + index + 1, data + index, (dim - index) * sizeof(*data));
Expand All @@ -150,12 +149,11 @@ void Array::insert(unsigned index, void *ptr)
}


void Array::insert(unsigned index, Array *a)
void Array::insert(size_t index, Array *a)
{
if (a)
{ unsigned d;

d = a->dim;
{
size_t d = a->dim;
reserve(d);
if (dim != index)
memmove(data + index + d, data + index, (dim - index) * sizeof(*data));
Expand All @@ -174,7 +172,7 @@ void Array::append(Array *a)
insert(dim, a);
}

void Array::remove(unsigned i)
void Array::remove(size_t i)
{
if (dim - i - 1)
memmove(data + i, data + i + 1, (dim - i - 1) * sizeof(data[0]));
Expand All @@ -183,8 +181,8 @@ void Array::remove(unsigned i)

char *Array::toChars()
{
unsigned len;
unsigned u;
size_t len;
size_t u;
char **buf;
char *str;
char *p;
Expand Down
4 changes: 2 additions & 2 deletions src/root/longdouble.c
Expand Up @@ -514,7 +514,7 @@ int ld_type(longdouble x)
return LD_TYPE_SNAN;
}

int ld_sprint(char* str, int fmt, longdouble x)
size_t ld_sprint(char* str, int fmt, longdouble x)
{
// fmt is 'a','A','f' or 'g'
if(fmt != 'a' && fmt != 'A')
Expand All @@ -537,7 +537,7 @@ int ld_sprint(char* str, int fmt, longdouble x)
return sprintf(str, x.sign ? "-INF" : "INF");
}

int len = 0;
size_t len = 0;
if(x.sign)
str[len++] = '-';
len += sprintf(str + len, mantissa & (1LL << 63) ? "0x1." : "0x0.");
Expand Down
6 changes: 3 additions & 3 deletions src/root/longdouble.h
Expand Up @@ -18,7 +18,7 @@
typedef real_t longdouble;

template<typename T> longdouble ldouble(T x) { return (longdouble) x; }
inline int ld_sprint(char* str, int fmt, longdouble x)
inline size_t ld_sprint(char* str, int fmt, longdouble x)
{
if(fmt == 'a' || fmt == 'A')
return x.formatHex(buffer, 46); // don't know the size here, but 46 is the max
Expand All @@ -34,7 +34,7 @@ typedef volatile long double volatile_longdouble;
// template<typename T> longdouble ldouble(T x) { return (longdouble) x; }
#define ldouble(x) ((longdouble)(x))

inline int ld_sprint(char* str, int fmt, longdouble x)
inline size_t ld_sprint(char* str, int fmt, longdouble x)
{
char sfmt[4] = "%Lg";
sfmt[2] = fmt;
Expand Down Expand Up @@ -247,7 +247,7 @@ template<> class _CRTIMP2_PURE std::numeric_limits<longdouble>
//_STCONSDEF(numeric_limits<longdouble>, int, min_exponent)
//_STCONSDEF(numeric_limits<longdouble>, int, min_exponent10)

int ld_sprint(char* str, int fmt, longdouble x);
size_t ld_sprint(char* str, int fmt, longdouble x);

#endif // !_MSC_VER

Expand Down
9 changes: 4 additions & 5 deletions src/root/response.c
Expand Up @@ -66,8 +66,8 @@

struct Narg
{
int argc; /* arg count */
int argvmax; /* dimension of nargv[] */
size_t argc; // arg count
size_t argvmax; // dimension of nargv[]
char **argv;
};

Expand All @@ -91,17 +91,16 @@ static int addargp(struct Narg *n, char *p)
return 0;
}

int response_expand(int *pargc, char ***pargv)
int response_expand(size_t *pargc, char ***pargv)
{
struct Narg n;
int i;
char *cp;
int recurse = 0;

n.argc = 0;
n.argvmax = 0; /* dimension of n.argv[] */
n.argv = NULL;
for(i=0; i<*pargc; ++i)
for (size_t i = 0; i < *pargc; ++i)
{
cp = (*pargv)[i];
if (*cp == '@')
Expand Down
14 changes: 7 additions & 7 deletions src/root/root.h
Expand Up @@ -271,11 +271,11 @@ struct OutBuffer : Object

struct Array : Object
{
unsigned dim;
size_t dim;
void **data;

private:
unsigned allocdim;
size_t allocdim;
#define SMALLARRAYCAP 1
void *smallarray[SMALLARRAYCAP]; // inline storage for small arrays

Expand All @@ -286,16 +286,16 @@ struct Array : Object
void mark();
char *toChars();

void reserve(unsigned nentries);
void setDim(unsigned newdim);
void reserve(size_t nentries);
void setDim(size_t newdim);
void fixDim();
void push(void *ptr);
void *pop();
void shift(void *ptr);
void insert(unsigned index, void *ptr);
void insert(unsigned index, Array *a);
void insert(size_t index, void *ptr);
void insert(size_t index, Array *a);
void append(Array *a);
void remove(unsigned i);
void remove(size_t i);
void zero();
void *tos();
void sort();
Expand Down

0 comments on commit 19389d2

Please sign in to comment.