From ddacb97e3ebcc089f8c894049e468865bd04024c Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Wed, 9 Jan 2002 00:04:56 +0000 Subject: [PATCH] Don't shadow global (standard C) "index" (noticed by LCLint). svn path=/trunk/yasm/; revision=429 --- libyasm/errwarn.c | 8 ++++---- libyasm/errwarn.h | 4 ++-- libyasm/linemgr.c | 31 +++++++++++++++++++------------ libyasm/linemgr.h | 4 ++-- src/errwarn.c | 8 ++++---- src/errwarn.h | 4 ++-- src/globals.c | 31 +++++++++++++++++++------------ src/globals.h | 4 ++-- src/linemgr.c | 31 +++++++++++++++++++------------ src/linemgr.h | 4 ++-- 10 files changed, 75 insertions(+), 54 deletions(-) diff --git a/libyasm/errwarn.c b/libyasm/errwarn.c index a80889b6..f64813b9 100644 --- a/libyasm/errwarn.c +++ b/libyasm/errwarn.c @@ -239,14 +239,14 @@ WarningNow(const char *fmt, ...) } void -ErrorAt(unsigned long index, const char *fmt, ...) +ErrorAt(unsigned long lindex, const char *fmt, ...) { /* XXX: Should insert into list instead of printing immediately */ va_list ap; const char *filename; unsigned long line; - line_lookup(index, &filename, &line); + line_lookup(lindex, &filename, &line); fprintf(stderr, "%s:%lu: ", filename?filename:"(NULL)", line); va_start(ap, fmt); vfprintf(stderr, fmt, ap); @@ -255,14 +255,14 @@ ErrorAt(unsigned long index, const char *fmt, ...) } void -WarningAt(unsigned long index, const char *fmt, ...) +WarningAt(unsigned long lindex, const char *fmt, ...) { /* XXX: Should insert into list instead of printing immediately */ va_list ap; const char *filename; unsigned long line; - line_lookup(index, &filename, &line); + line_lookup(lindex, &filename, &line); fprintf(stderr, "%s:%lu: %s ", filename?filename:"NULL", line, _("warning:")); va_start(ap, fmt); diff --git a/libyasm/errwarn.h b/libyasm/errwarn.h index b50fa08b..d48c539a 100644 --- a/libyasm/errwarn.h +++ b/libyasm/errwarn.h @@ -46,8 +46,8 @@ void Warning(const char *, ...) /*@printflike@*/; * called in line order from a parser. The *At() functions are much slower, * at least in the current implementation. */ -void ErrorAt(unsigned long index, const char *, ...) /*@printflike@*/; -void WarningAt(unsigned long index, const char *, ...) /*@printflike@*/; +void ErrorAt(unsigned long lindex, const char *, ...) /*@printflike@*/; +void WarningAt(unsigned long lindex, const char *, ...) /*@printflike@*/; /* These two functions immediately output the error or warning, with no file * or line information. They should be used for errors and warnings outside diff --git a/libyasm/linemgr.c b/libyasm/linemgr.c index b57dc2da..3be4d855 100644 --- a/libyasm/linemgr.c +++ b/libyasm/linemgr.c @@ -49,14 +49,14 @@ typedef struct line_index_mapping { /* "original" source base line number */ unsigned long line; /* "original" source line number increment (for following lines) */ - unsigned int line_inc; + unsigned long line_inc; } line_index_mapping; /* Shared storage for filenames */ static /*@only@*/ /*@null@*/ HAMT *filename_table = NULL; /* Virtual line number. Uniquely specifies every line read by the parser. */ unsigned long line_index = 1; -static line_index_mapping_head *line_index_map = NULL; +static /*@only@*/ /*@null@*/ line_index_mapping_head *line_index_map = NULL; /* Global assembler options. */ unsigned int asm_options = 0; @@ -105,13 +105,17 @@ void line_shutdown(void) { line_index_mapping *mapping, *mapping2; - mapping = STAILQ_FIRST(line_index_map); - while (mapping) { - mapping2 = STAILQ_NEXT(mapping, link); - xfree(mapping); - mapping = mapping2; + + if (line_index_map) { + mapping = STAILQ_FIRST(line_index_map); + while (mapping) { + mapping2 = STAILQ_NEXT(mapping, link); + xfree(mapping); + mapping = mapping2; + } + xfree(line_index_map); + line_index_map = NULL; } - xfree(line_index_map); if (filename_table) { HAMT_delete(filename_table, filename_delete_one); @@ -120,21 +124,24 @@ line_shutdown(void) } void -line_lookup(unsigned long index, const char **filename, unsigned long *line) +line_lookup(unsigned long lindex, const char **filename, unsigned long *line) { line_index_mapping *mapping, *mapping2; - assert(index <= line_index); + assert(lindex <= line_index); /* Linearly search through map to find highest line_index <= index */ + assert(line_index_map != NULL); mapping = STAILQ_FIRST(line_index_map); while (mapping) { mapping2 = STAILQ_NEXT(mapping, link); - if (!mapping2 || mapping2->index > index) + if (!mapping2 || mapping2->index > lindex) break; mapping = mapping2; } + assert(mapping != NULL); + *filename = mapping->filename; - *line = mapping->line+mapping->line_inc*(index-mapping->index); + *line = mapping->line+mapping->line_inc*(lindex-mapping->index); } diff --git a/libyasm/linemgr.h b/libyasm/linemgr.h index 690b8d65..54ffec47 100644 --- a/libyasm/linemgr.h +++ b/libyasm/linemgr.h @@ -40,7 +40,7 @@ extern int indent_level; void line_set(const char *filename, unsigned long line, unsigned long line_inc); void line_shutdown(void); -void line_lookup(unsigned long index, const char **filename, - unsigned long *line); +void line_lookup(unsigned long lindex, /*@out@*/ const char **filename, + /*@out@*/ unsigned long *line); #endif diff --git a/src/errwarn.c b/src/errwarn.c index a80889b6..f64813b9 100644 --- a/src/errwarn.c +++ b/src/errwarn.c @@ -239,14 +239,14 @@ WarningNow(const char *fmt, ...) } void -ErrorAt(unsigned long index, const char *fmt, ...) +ErrorAt(unsigned long lindex, const char *fmt, ...) { /* XXX: Should insert into list instead of printing immediately */ va_list ap; const char *filename; unsigned long line; - line_lookup(index, &filename, &line); + line_lookup(lindex, &filename, &line); fprintf(stderr, "%s:%lu: ", filename?filename:"(NULL)", line); va_start(ap, fmt); vfprintf(stderr, fmt, ap); @@ -255,14 +255,14 @@ ErrorAt(unsigned long index, const char *fmt, ...) } void -WarningAt(unsigned long index, const char *fmt, ...) +WarningAt(unsigned long lindex, const char *fmt, ...) { /* XXX: Should insert into list instead of printing immediately */ va_list ap; const char *filename; unsigned long line; - line_lookup(index, &filename, &line); + line_lookup(lindex, &filename, &line); fprintf(stderr, "%s:%lu: %s ", filename?filename:"NULL", line, _("warning:")); va_start(ap, fmt); diff --git a/src/errwarn.h b/src/errwarn.h index b50fa08b..d48c539a 100644 --- a/src/errwarn.h +++ b/src/errwarn.h @@ -46,8 +46,8 @@ void Warning(const char *, ...) /*@printflike@*/; * called in line order from a parser. The *At() functions are much slower, * at least in the current implementation. */ -void ErrorAt(unsigned long index, const char *, ...) /*@printflike@*/; -void WarningAt(unsigned long index, const char *, ...) /*@printflike@*/; +void ErrorAt(unsigned long lindex, const char *, ...) /*@printflike@*/; +void WarningAt(unsigned long lindex, const char *, ...) /*@printflike@*/; /* These two functions immediately output the error or warning, with no file * or line information. They should be used for errors and warnings outside diff --git a/src/globals.c b/src/globals.c index b57dc2da..3be4d855 100644 --- a/src/globals.c +++ b/src/globals.c @@ -49,14 +49,14 @@ typedef struct line_index_mapping { /* "original" source base line number */ unsigned long line; /* "original" source line number increment (for following lines) */ - unsigned int line_inc; + unsigned long line_inc; } line_index_mapping; /* Shared storage for filenames */ static /*@only@*/ /*@null@*/ HAMT *filename_table = NULL; /* Virtual line number. Uniquely specifies every line read by the parser. */ unsigned long line_index = 1; -static line_index_mapping_head *line_index_map = NULL; +static /*@only@*/ /*@null@*/ line_index_mapping_head *line_index_map = NULL; /* Global assembler options. */ unsigned int asm_options = 0; @@ -105,13 +105,17 @@ void line_shutdown(void) { line_index_mapping *mapping, *mapping2; - mapping = STAILQ_FIRST(line_index_map); - while (mapping) { - mapping2 = STAILQ_NEXT(mapping, link); - xfree(mapping); - mapping = mapping2; + + if (line_index_map) { + mapping = STAILQ_FIRST(line_index_map); + while (mapping) { + mapping2 = STAILQ_NEXT(mapping, link); + xfree(mapping); + mapping = mapping2; + } + xfree(line_index_map); + line_index_map = NULL; } - xfree(line_index_map); if (filename_table) { HAMT_delete(filename_table, filename_delete_one); @@ -120,21 +124,24 @@ line_shutdown(void) } void -line_lookup(unsigned long index, const char **filename, unsigned long *line) +line_lookup(unsigned long lindex, const char **filename, unsigned long *line) { line_index_mapping *mapping, *mapping2; - assert(index <= line_index); + assert(lindex <= line_index); /* Linearly search through map to find highest line_index <= index */ + assert(line_index_map != NULL); mapping = STAILQ_FIRST(line_index_map); while (mapping) { mapping2 = STAILQ_NEXT(mapping, link); - if (!mapping2 || mapping2->index > index) + if (!mapping2 || mapping2->index > lindex) break; mapping = mapping2; } + assert(mapping != NULL); + *filename = mapping->filename; - *line = mapping->line+mapping->line_inc*(index-mapping->index); + *line = mapping->line+mapping->line_inc*(lindex-mapping->index); } diff --git a/src/globals.h b/src/globals.h index 690b8d65..54ffec47 100644 --- a/src/globals.h +++ b/src/globals.h @@ -40,7 +40,7 @@ extern int indent_level; void line_set(const char *filename, unsigned long line, unsigned long line_inc); void line_shutdown(void); -void line_lookup(unsigned long index, const char **filename, - unsigned long *line); +void line_lookup(unsigned long lindex, /*@out@*/ const char **filename, + /*@out@*/ unsigned long *line); #endif diff --git a/src/linemgr.c b/src/linemgr.c index b57dc2da..3be4d855 100644 --- a/src/linemgr.c +++ b/src/linemgr.c @@ -49,14 +49,14 @@ typedef struct line_index_mapping { /* "original" source base line number */ unsigned long line; /* "original" source line number increment (for following lines) */ - unsigned int line_inc; + unsigned long line_inc; } line_index_mapping; /* Shared storage for filenames */ static /*@only@*/ /*@null@*/ HAMT *filename_table = NULL; /* Virtual line number. Uniquely specifies every line read by the parser. */ unsigned long line_index = 1; -static line_index_mapping_head *line_index_map = NULL; +static /*@only@*/ /*@null@*/ line_index_mapping_head *line_index_map = NULL; /* Global assembler options. */ unsigned int asm_options = 0; @@ -105,13 +105,17 @@ void line_shutdown(void) { line_index_mapping *mapping, *mapping2; - mapping = STAILQ_FIRST(line_index_map); - while (mapping) { - mapping2 = STAILQ_NEXT(mapping, link); - xfree(mapping); - mapping = mapping2; + + if (line_index_map) { + mapping = STAILQ_FIRST(line_index_map); + while (mapping) { + mapping2 = STAILQ_NEXT(mapping, link); + xfree(mapping); + mapping = mapping2; + } + xfree(line_index_map); + line_index_map = NULL; } - xfree(line_index_map); if (filename_table) { HAMT_delete(filename_table, filename_delete_one); @@ -120,21 +124,24 @@ line_shutdown(void) } void -line_lookup(unsigned long index, const char **filename, unsigned long *line) +line_lookup(unsigned long lindex, const char **filename, unsigned long *line) { line_index_mapping *mapping, *mapping2; - assert(index <= line_index); + assert(lindex <= line_index); /* Linearly search through map to find highest line_index <= index */ + assert(line_index_map != NULL); mapping = STAILQ_FIRST(line_index_map); while (mapping) { mapping2 = STAILQ_NEXT(mapping, link); - if (!mapping2 || mapping2->index > index) + if (!mapping2 || mapping2->index > lindex) break; mapping = mapping2; } + assert(mapping != NULL); + *filename = mapping->filename; - *line = mapping->line+mapping->line_inc*(index-mapping->index); + *line = mapping->line+mapping->line_inc*(lindex-mapping->index); } diff --git a/src/linemgr.h b/src/linemgr.h index 690b8d65..54ffec47 100644 --- a/src/linemgr.h +++ b/src/linemgr.h @@ -40,7 +40,7 @@ extern int indent_level; void line_set(const char *filename, unsigned long line, unsigned long line_inc); void line_shutdown(void); -void line_lookup(unsigned long index, const char **filename, - unsigned long *line); +void line_lookup(unsigned long lindex, /*@out@*/ const char **filename, + /*@out@*/ unsigned long *line); #endif -- 2.40.0