16
16
*/
17
17
18
18
#include <stdarg.h>
19
+ #define _GNU_SOURCE /* for asprintf */
19
20
#include <stdlib.h>
20
21
#include <stdio.h>
21
22
#include <malloc.h>
@@ -44,25 +45,6 @@ static int printable_label(const char *s)
44
45
return p - s ;
45
46
}
46
47
47
- static const char * alloc_printf (const char * fmt , ...)
48
- {
49
- va_list ap ;
50
- int n ;
51
- char * s ;
52
-
53
- va_start (ap , fmt );
54
- n = vsnprintf (NULL , 0 , fmt , ap );
55
- va_end (ap );
56
-
57
- s = malloc (n + 1 );
58
-
59
- va_start (ap , fmt );
60
- vsnprintf (s , n + 1 , fmt , ap );
61
- va_end (ap );
62
-
63
- return s ;
64
- }
65
-
66
48
const char * fpvm_parse (const char * expr , int start_token ,
67
49
struct parser_comm * comm )
68
50
{
@@ -77,7 +59,7 @@ const char *fpvm_parse(const char *expr, int start_token,
77
59
int tok ;
78
60
struct id * identifier ;
79
61
void * p ;
80
- const char * error = NULL ;
62
+ char * error = NULL ;
81
63
82
64
s = new_scanner ((unsigned char * )expr );
83
65
p = ParseAlloc (malloc );
@@ -103,7 +85,7 @@ const char *fpvm_parse(const char *expr, int start_token,
103
85
104
86
state .id = identifier ;
105
87
if (tok == TOK_ERROR ) {
106
- error = alloc_printf (
88
+ asprintf ( & error ,
107
89
"FPVM, line %d: scan error near '%c'" ,
108
90
s -> lineno , printable_char (s -> cursor [-1 ]));
109
91
ParseFree (p , free );
@@ -118,7 +100,7 @@ const char *fpvm_parse(const char *expr, int start_token,
118
100
delete_scanner (s );
119
101
120
102
if (!state .success ) {
121
- error = alloc_printf (
103
+ asprintf ( & error ,
122
104
"FPVM, line %d: %s near '%.*s'" ,
123
105
state .error_lineno ,
124
106
state .error ? state .error : "parse error" ,
0 commit comments