Skip to content

Commit

Permalink
PVS-Studio recommended changes to tk
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Nov 16, 2012
1 parent ebbf254 commit 22a4264
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 94 deletions.
27 changes: 18 additions & 9 deletions src/backend/code.h
Expand Up @@ -82,15 +82,6 @@ void code_term(void);

#define code_next(c) ((c)->next)

/**********************************
* Set value in regimmed for reg.
* NOTE: For 16 bit generator, this is always a (targ_short) sign-extended
* value.
*/

#define regimmed_set(reg,e) \
(regcon.immed.value[reg] = (e),regcon.immed.mval |= 1 << (reg))

extern con_t regcon;

/****************************
Expand Down Expand Up @@ -646,6 +637,24 @@ inline regm_t Symbol::Spregm()
}


/**********************************
* Set value in regimmed for reg.
* NOTE: For 16 bit generator, this is always a (targ_short) sign-extended
* value.
*/

#if 1
inline void regimmed_set(int reg, targ_size_t e)
{
regcon.immed.value[reg] = e;
regcon.immed.mval |= 1 << (reg);
//printf("regimmed_set %s %d\n", regm_str(mask[reg]), (int)e);
}
#else
#define regimmed_set(reg,e) \
(regcon.immed.value[reg] = (e),regcon.immed.mval |= 1 << (reg))
#endif

#if __cplusplus && TX86
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/backend/global.h
Expand Up @@ -451,7 +451,7 @@ int elemisone(elem *);
/* msc.c */
targ_size_t size(tym_t);
Symbol *symboldata(targ_size_t offset,tym_t ty);
int dom(block *A , block *B);
bool dom(block *A , block *B);
unsigned revop(unsigned op);
unsigned invrel(unsigned op);
int binary(const char *p, const char ** tab, int high);
Expand Down
4 changes: 2 additions & 2 deletions src/backend/gloop.c
Expand Up @@ -329,10 +329,10 @@ void compdom()
* Return !=0 if block A dominates block B.
*/

HINT dom(block *A,block *B)
bool dom(block *A,block *B)
{
assert(A && B && dfo && dfo[A->Bdfoidx] == A);
return vec_testbit(A->Bdfoidx,B->Bdom);
return vec_testbit(A->Bdfoidx,B->Bdom) != 0;
}

/**********************
Expand Down
14 changes: 7 additions & 7 deletions src/tk/filespec.c
Expand Up @@ -52,8 +52,8 @@
/**********************/

char * filespecaddpath(const char *path,const char *filename)
{ register char *filespec;
register unsigned pathlen;
{ char *filespec;
size_t pathlen;

if (!path || (pathlen = strlen(path)) == 0)
filespec = mem_strdup(filename);
Expand Down Expand Up @@ -194,8 +194,8 @@ char * filespecrootpath(char *filespec)
/**********************/

char * filespecdotext(const char *filespec)
{ register const char *p;
register int len;
{ const char *p;
size_t len;

if ((p = filespec) != NULL)
{ p += (len = strlen(p));
Expand Down Expand Up @@ -246,12 +246,12 @@ char * filespecforceext(const char *filespec,const char *ext)
{ register char *p;
register const char *pext;

if (*ext == '.')
if (ext && *ext == '.')
ext++;
if ((p = (char *)filespec) != NULL)
{ pext = filespecdotext(filespec);
if (ext)
{ int n = pext - filespec;
{ size_t n = pext - filespec;
p = (char *) mem_malloc(n + 1 + strlen(ext) + 1);
if (p)
{ memcpy(p,filespec,n);
Expand All @@ -277,7 +277,7 @@ char * filespecdefaultext(const char *filespec,const char *ext)
p = mem_strdup(filespec);
}
else
{ int n = pext - filespec;
{ size_t n = pext - filespec;
p = (char *) mem_malloc(n + 1 + strlen(ext) + 1);
if (p)
{
Expand Down
44 changes: 19 additions & 25 deletions src/tk/mem.c
Expand Up @@ -153,12 +153,9 @@ char *mem_strdup_debug(const char *s,const char *file,int line)
#else
char *mem_strdup(const char *s)
{
char *p;
int len;

if (s)
{ len = strlen(s) + 1;
p = (char *) mem_malloc(len);
{ size_t len = strlen(s) + 1;
char *p = (char *) mem_malloc(len);
if (p)
return (char *)memcpy(p,s,len);
}
Expand Down Expand Up @@ -279,8 +276,8 @@ void __cdecl operator delete[](void *p)

#if MEM_DEBUG

static long mem_maxalloc; /* max # of bytes allocated */
static long mem_numalloc; /* current # of bytes allocated */
static size_t mem_maxalloc; /* max # of bytes allocated */
static size_t mem_numalloc; /* current # of bytes allocated */

#define BEFOREVAL 0x4F464542 /* value to detect underrun */
#define AFTERVAL 0x45544641 /* value to detect overrun */
Expand Down Expand Up @@ -318,7 +315,7 @@ static struct mem_debug
struct mem_debug *Mprev; /* previous value in list */
const char *Mfile; /* filename of where allocated */
int Mline; /* line number of where allocated */
unsigned Mnbytes; /* size of the allocation */
size_t Mnbytes; /* size of the allocation */
unsigned long Mbeforeval; /* detect underrun of data */
char data[1]; /* the data actually allocated */
} mem_alloclist =
Expand Down Expand Up @@ -383,17 +380,17 @@ static void mem_fillin(const char *fil, int lin)
* called.
*/

void *mem_calloc(unsigned u)
void *mem_calloc(size_t u)
{
return mem_calloc_debug(u,__FILE__,__LINE__);
}

void *mem_malloc(unsigned u)
void *mem_malloc(size_t u)
{
return mem_malloc_debug(u,__FILE__,__LINE__);
}

void *mem_realloc(void *p, unsigned u)
void *mem_realloc(void *p, size_t u)
{
return mem_realloc_debug(p,u,__FILE__,__LINE__);
}
Expand All @@ -415,7 +412,7 @@ void mem_freefp(void *p)
* Debug versions of mem_calloc(), mem_free() and mem_realloc().
*/

void *mem_malloc_debug(unsigned n, const char *fil, int lin)
void *mem_malloc_debug(size_t n, const char *fil, int lin)
{ void *p;

p = mem_calloc_debug(n,fil,lin);
Expand All @@ -424,7 +421,7 @@ void *mem_malloc_debug(unsigned n, const char *fil, int lin)
return p;
}

void *mem_calloc_debug(unsigned n, const char *fil, int lin)
void *mem_calloc_debug(size_t n, const char *fil, int lin)
{
struct mem_debug *dl;

Expand Down Expand Up @@ -517,7 +514,7 @@ void mem_free_debug(void *ptr, const char *fil, int lin)
* Debug version of mem_realloc().
*/

void *mem_realloc_debug(void *oldp, unsigned n, const char *fil, int lin)
void *mem_realloc_debug(void *oldp, size_t n, const char *fil, int lin)
{ void *p;
struct mem_debug *dl;

Expand Down Expand Up @@ -613,7 +610,7 @@ void mem_checkptr(void *p)

/***************************/

void *mem_malloc(unsigned numbytes)
void *mem_malloc(size_t numbytes)
{ void *p;

if (numbytes == 0)
Expand All @@ -637,7 +634,7 @@ void *mem_malloc(unsigned numbytes)

/***************************/

void *mem_calloc(unsigned numbytes)
void *mem_calloc(size_t numbytes)
{ void *p;

if (numbytes == 0)
Expand All @@ -661,7 +658,7 @@ void *mem_calloc(unsigned numbytes)

/***************************/

void *mem_realloc(void *oldmem_ptr,unsigned newnumbytes)
void *mem_realloc(void *oldmem_ptr,size_t newnumbytes)
{ void *p;

if (oldmem_ptr == NULL)
Expand Down Expand Up @@ -705,7 +702,7 @@ static size_t heapleft;

#if 0 && __SC__ && __INTSIZE == 4 && __I86__ && !_DEBUG_TRACE && _WIN32 && (SCC || SCPP || JAVA)

__declspec(naked) void *mem_fmalloc(unsigned numbytes)
__declspec(naked) void *mem_fmalloc(size_t numbytes)
{
__asm
{
Expand Down Expand Up @@ -750,7 +747,7 @@ L18: add heap,EBX

#else

void *mem_fmalloc(unsigned numbytes)
void *mem_fmalloc(size_t numbytes)
{ void *p;

//printf("fmalloc(%d)\n",numbytes);
Expand Down Expand Up @@ -806,7 +803,7 @@ void *mem_fmalloc(unsigned numbytes)

/***************************/

void *mem_fcalloc(unsigned numbytes)
void *mem_fcalloc(size_t numbytes)
{ void *p;

p = mem_fmalloc(numbytes);
Expand All @@ -817,12 +814,9 @@ void *mem_fcalloc(unsigned numbytes)

char *mem_fstrdup(const char *s)
{
char *p;
int len;

if (s)
{ len = strlen(s) + 1;
p = (char *) mem_fmalloc(len);
{ size_t len = strlen(s) + 1;
char *p = (char *) mem_fmalloc(len);
if (p)
return (char *)memcpy(p,s,len);
}
Expand Down
26 changes: 14 additions & 12 deletions src/tk/mem.h
@@ -1,5 +1,5 @@
/*_ mem.h */
/* Copyright 1986-1997 by Walter Bright */
/* Copyright 1986-2012 by Walter Bright */
/* All Rights Reserved */
/* Written by Walter Bright */

Expand All @@ -10,6 +10,8 @@
#pragma once
#endif

#include <stdio.h> // for size_t

/*
* Memory management routines.
*
Expand Down Expand Up @@ -133,8 +135,8 @@ void mem_checkptr(void *ptr);
/***************************
* Allocate and return a pointer to numbytes of storage.
* Use:
* void *mem_malloc(unsigned numbytes);
* void *mem_calloc(unsigned numbytes); allocated memory is cleared
* void *mem_malloc(size_t numbytes);
* void *mem_calloc(size_t numbytes); allocated memory is cleared
* Input:
* numbytes Number of bytes to allocate
* Returns:
Expand All @@ -144,16 +146,16 @@ void mem_checkptr(void *ptr);
* return NULL
*/

void *mem_malloc(unsigned);
void *mem_calloc(unsigned);
void *mem_malloc(size_t);
void *mem_calloc(size_t);

/*****************************
* Reallocate memory.
* Use:
* void *mem_realloc(void *ptr,unsigned numbytes);
* void *mem_realloc(void *ptr,size_t numbytes);
*/

void *mem_realloc(void *,unsigned);
void *mem_realloc(void *,size_t);

/*****************************
* Free memory allocated by mem_malloc(), mem_calloc() or mem_realloc().
Expand Down Expand Up @@ -202,8 +204,8 @@ void mem_term(void);
#define mem_ffree mem_free
#define mem_fstrdup mem_strdup
#else
void *mem_fmalloc(unsigned);
void *mem_fcalloc(unsigned);
void *mem_fmalloc(size_t);
void *mem_fcalloc(size_t);
#define mem_ffree(p) ((void)0)
char *mem_fstrdup(const char *);
#endif
Expand Down Expand Up @@ -251,9 +253,9 @@ extern char *__mem_file;
#define mem_free(p) mem_free_debug((p),__FILE__,__LINE__)

char *mem_strdup_debug (const char *,const char *,int);
void *mem_calloc_debug (unsigned,const char *,int);
void *mem_malloc_debug (unsigned,const char *,int);
void *mem_realloc_debug (void *,unsigned,const char *,int);
void *mem_calloc_debug (size_t,const char *,int);
void *mem_malloc_debug (size_t,const char *,int);
void *mem_realloc_debug (void *,size_t,const char *,int);
void mem_free_debug (void *,const char *,int);
void mem_freefp (void *);

Expand Down

0 comments on commit 22a4264

Please sign in to comment.