[m-dev.] for review: demangle instance declarations
Fergus Henderson
fjh at cs.mu.OZ.AU
Fri Feb 5 02:25:53 AEDT 1999
On 05-Feb-1999, David Glen JEFFERY <dgj at hydra.cs.mu.oz.au> wrote:
> > + char name[1000];
>
> Could you #define away that magic number, please? You don't seem to use the
> number elsewhere (eg. you use strlen(name)), but it still just looks bad.
Estimated hours taken: 0.1
util/mdemangle.c:
Use a macro rather than hard-coding the magic number 1000
in several places.
Index: util/mdemangle.c
===================================================================
RCS file: /home/mercury1/repository/mercury/util/mdemangle.c,v
retrieving revision 1.32
diff -u -r1.32 mdemangle.c
--- mdemangle.c 1999/02/04 14:58:38 1.32
+++ mdemangle.c 1999/02/04 15:23:31
@@ -27,6 +27,9 @@
#include <stdio.h>
#include "mercury_std.h"
+/* We used this for the size of fixed-length buffers in a few places <sigh> */
+#define MAX_SYMBOL_LENGTH 1000
+
static void demangle(const char *name);
static const char *strip_module_name(char **start_ptr, char *end,
const char *trailing_context[]);
@@ -67,7 +70,7 @@
** every valid C identifier in the input
*/
for (;;) {
- char buf[1000];
+ char buf[MAX_SYMBOL_LENGTH];
size_t len = 0;
int c = getchar();
while (c != EOF && (isalnum(c) || c == '_')) {
@@ -143,7 +146,7 @@
NULL
};
- char name[1000];
+ char name[MAX_SYMBOL_LENGTH];
char *start = name;
const char *module = ""; /* module name */
char *end = name + strlen(orig_name);
@@ -164,7 +167,7 @@
enum { COMMON, INFO, LAYOUT, FUNCTORS } data_category;
const char * class_name;
int class_arity;
- char class_arg_buf[1000];
+ char class_arg_buf[MAX_SYMBOL_LENGTH];
int class_arg_num;
const char* class_arg;
@@ -785,7 +788,7 @@
** ASCII codes back into an identifier.
*/
if (strncmp(str, "f_", 2) == 0) {
- char buf[1000];
+ char buf[MAX_SYMBOL_LENGTH];
char *num = str + 2;
int count = 0;
while (num < end) {
--
Fergus Henderson <fjh at cs.mu.oz.au> | "Binaries may die
WWW: <http://www.cs.mu.oz.au/~fjh> | but source code lives forever"
PGP: finger fjh at 128.250.37.3 | -- leaked Microsoft memo.
More information about the developers
mailing list