The function flex_alloc() was just a wrapper around malloc(). Since this only added unclarity, and the flex_alloc() function is likely a legacy of olden times, remove it in favor of calls to malloc() directly.
Style elements cleaned up:
* superfluous spacing around parentheses
* non-constant initialization in variable declarations
* needless casts
* almost all uses of assignments as subexpressions
char *t;
size_t tsz;
- t = flex_alloc (tsz = strlen (fmt) + strlen (s) + 1);
+ tsz = strlen(fmt) + strlen(s) + 1;
+ t = malloc(tsz);
if (!t)
flexfatal (_("Allocation of buffer to print string failed"));
snprintf (t, tsz, fmt, s);
char *dst, *t;
const char *src;
- t = flex_alloc (strlen ("#line \"\"\n") + /* constant parts */
+ t = malloc(strlen("#line \"\"\n") + /* constant parts */
2 * strlen (filename) + /* filename with possibly all backslashes escaped */
(int) (1 + log10 (abs (lineno))) + /* line number */
1); /* NUL */
size_t strsz;
val = val?val:"";
- str = (char*)flex_alloc(strsz = strlen(fmt) + strlen(def) + strlen(val) + 2);
+ strsz = strlen(fmt) + strlen(def) + strlen(val) + 2;
+ str = malloc(strsz);
if (!str)
flexfatal (_("Allocation of buffer for m4 def failed"));
char * str;
size_t strsz;
- str = (char*)flex_alloc(strsz = strlen(fmt) + strlen(def) + 2);
+ strsz = strlen(fmt) + strlen(def) + 2;
+ str = malloc(strsz);
if (!str)
flexfatal (_("Allocation of buffer for m4 undef failed"));
va_list ap;
/* allocate and initialize new filter */
- f = (struct filter *) flex_alloc (sizeof (struct filter));
+ f = malloc(sizeof(struct filter));
if (!f)
- flexerror (_("flex_alloc failed (f) in filter_create_ext"));
+ flexerror(_("malloc failed (f) in filter_create_ext"));
memset (f, 0, sizeof (*f));
f->filter_func = NULL;
f->extra = NULL;
/* allocate argv, and populate it with the argument list. */
max_args = 8;
- f->argv =
- (const char **) flex_alloc (sizeof (char *) *
- (max_args + 1));
+ f->argv = malloc(sizeof(char *) * (max_args + 1));
if (!f->argv)
- flexerror (_("flex_alloc failed (f->argv) in filter_create_ext"));
+ flexerror(_("malloc failed (f->argv) in filter_create_ext"));
f->argv[f->argc++] = cmd;
va_start (ap, cmd);
struct filter *f;
/* allocate and initialize new filter */
- f = (struct filter *) flex_alloc (sizeof (struct filter));
+ f = malloc(sizeof(struct filter));
if (!f)
- flexerror (_("flex_alloc failed in filter_create_int"));
+ flexerror(_("malloc failed in filter_create_int"));
memset (f, 0, sizeof (*f));
f->next = NULL;
f->argc = 0;
fprintf (to_c, "m4_define( [[M4_YY_OUTFILE_NAME]],[[%s]])m4_dnl\n",
outfilename ? outfilename : "<stdout>");
- buf = (char *) flex_alloc (readsz);
+ buf = malloc(readsz);
if (!buf)
- flexerror (_("flex_alloc failed in filter_tee_header"));
+ flexerror(_("malloc failed in filter_tee_header"));
while (fgets (buf, readsz, stdin)) {
fputs (buf, to_c);
if (write_header)
if (!chain)
return 0;
- buf = (char *) flex_alloc (readsz);
+ buf = malloc(readsz);
if (!buf)
- flexerror (_("flex_alloc failed in filter_fix_linedirs"));
+ flexerror(_("malloc failed in filter_fix_linedirs"));
while (fgets (buf, readsz, stdin)) {
void *allocate_array PROTO ((int, size_t));
void *reallocate_array PROTO ((void *, int, size_t));
-void *flex_alloc PROTO ((size_t));
void *flex_realloc PROTO ((void *, size_t));
void flex_free PROTO ((void *));
char *str, *fmt = "#define %s %d\n";
size_t strsz;
- str = (char*)flex_alloc(strsz = strlen(fmt) + strlen(scname[i]) + (int)(1 + log10(i)) + 2);
+ strsz = strlen(fmt) + strlen(scname[i]) + (int)(1 + log10(i)) + 2;
+ str = malloc(strsz);
if (!str)
flexfatal(_("allocation of macro definition failed"));
snprintf(str, strsz, fmt, scname[i], i - 1);
{
if(!sko_stack){
sko_sz = 1;
- sko_stack = (struct sko_state*)flex_alloc(sizeof(struct sko_state)*sko_sz);
+ sko_stack = malloc(sizeof(struct sko_state) * sko_sz);
if (!sko_stack)
flexfatal(_("allocation of sko_stack failed"));
sko_len = 0;
void *mem;
size_t num_bytes = element_size * size;
- mem = flex_alloc (num_bytes);
+ mem = malloc(num_bytes);
if (!mem)
flexfatal (_
("memory allocation failed in allocate_array()"));
/* The following is only needed when building flex's parser using certain
* broken versions of bison.
+ *
+ * XXX: this is should go soon
*/
void *yy_flex_xmalloc (int size)
{
- void *result = flex_alloc ((size_t) size);
+ void *result;
+ result = malloc(size);
if (!result)
flexfatal (_
("memory allocation failed in yy_flex_xmalloc()"));
const int errbuf_sz = 200;
char *errbuf, *rxerr;
- errbuf = (char*)flex_alloc(errbuf_sz *sizeof(char));
+ errbuf = malloc(errbuf_sz * sizeof(char));
if (!errbuf)
flexfatal(_("Unable to allocate buffer to report regcomp"));
- rxerr = (char*)flex_alloc(errbuf_sz *sizeof(char));
+ rxerr = malloc(errbuf_sz * sizeof(char));
if (!rxerr)
flexfatal(_("Unable to allocate buffer for regerror"));
regerror (err, preg, rxerr, errbuf_sz);
if (m == NULL || m->rm_so < 0)
return NULL;
len = m->rm_eo - m->rm_so;
- str = (char *) flex_alloc ((len + 1) * sizeof (char));
+ str = malloc((len + 1) * sizeof(char));
if (!str)
flexfatal(_("Unable to allocate a copy of the match"));
strncpy (str, src + m->rm_so, len);
/* Wrapper routines for accessing the scanner's malloc routines. */
-void *flex_alloc( size_t size )
- {
- return malloc(size);
- }
-
void *flex_realloc( void *ptr, size_t size )
{
return realloc(ptr, size);
sf_init (void)
{
assert(_sf_stk == NULL);
- _sf_stk = (scanflags_t*) flex_alloc ( sizeof(scanflags_t) * (_sf_max = 32));
+ _sf_max = 32;
+ _sf_stk = malloc(sizeof(scanflags_t) * _sf_max);
if (!_sf_stk)
lerr_fatal(_("Unable to allocate %zu of stack"), sizeof(scanflags_t));
_sf_stk[_sf_top_ix] = 0;
}
/* create new entry */
- new_entry = (struct hash_entry *)
- flex_alloc (sizeof (struct hash_entry));
+ new_entry = malloc(sizeof(struct hash_entry));
if (new_entry == NULL)
flexfatal (_("symbol table memory allocation failed"));
void *allocate_array PROTO((int, size_t));
void *reallocate_array PROTO((void*, int, size_t));
-void *flex_alloc PROTO((size_t));
void *flex_realloc PROTO((void*, size_t));
void flex_free PROTO((void*));
register void *mem;
size_t num_bytes = element_size * size;
- mem = flex_alloc( num_bytes );
+ mem = malloc(num_bytes);
if ( ! mem )
flexfatal(
_( "memory allocation failed in allocate_array()" ) );
void *yy_flex_xmalloc( size )
int size;
{
- void *result = flex_alloc( (size_t) size );
+ void *result;
+ result = malloc(size);
if ( ! result )
flexfatal(
_( "memory allocation failed in yy_flex_xmalloc()" ) );
/* Wrapper routines for accessing the scanner's malloc routines. */
-void *flex_alloc( size )
-size_t size;
- {
- return malloc(size);
- }
-
void *flex_realloc( ptr, size )
void *ptr;
size_t size;