@@ -106,8 +106,8 @@ enum tok {
106106 TVAR ,
107107};
108108
109- static enum tok
110- nexttok (const char * * pos , struct strbuf * buf )
109+ static int
110+ nexttok (enum tok * tok , const char * * pos , struct strbuf * buf )
111111{
112112 const char * p ;
113113 int r ;
@@ -121,8 +121,10 @@ nexttok(const char **pos, struct strbuf *buf)
121121 case '{' :
122122 * pos = p ;
123123 if (buf -> len > 0 )
124- return TTEXT ;
125- return TVAR ;
124+ * tok = TTEXT ;
125+ else
126+ * tok = TVAR ;
127+ return 1 ;
126128 case '\\' :
127129 switch (* ++ p ) {
128130 case '\\' : r = strbuf_putc (buf , '\\' ); break ;
@@ -148,7 +150,8 @@ nexttok(const char **pos, struct strbuf *buf)
148150 }
149151 if (buf -> len > 0 ) {
150152 * pos = p ;
151- return TTEXT ;
153+ * tok = TTEXT ;
154+ return 1 ;
152155 }
153156 p ++ ;
154157 return 0 ;
@@ -520,21 +523,25 @@ xbps_fmt_parse(const char *format)
520523 struct xbps_fmt * tmp ;
521524 enum tok t ;
522525
523- t = nexttok (& pos , & buf );
526+ r = nexttok (& t , & pos , & buf );
527+ if (r < 0 )
528+ goto err ;
524529
525530 tmp = realloc (fmt , sizeof (* fmt )* (n + 1 ));
526531 if (!tmp )
527532 goto err_errno ;
528533 fmt = tmp ;
529534 memset (& fmt [n ], '\0' , sizeof (struct xbps_fmt ));
530535
531- if (t == 0 )
536+ if (r == 0 )
532537 goto out ;
533538 if (t == TTEXT ) {
534539 fmt [n ].prefix = strndup (buf .mem , buf .len );
535540 if (!fmt [n ].prefix )
536541 goto err_errno ;
537- t = nexttok (& pos , & buf );
542+ r = nexttok (& t , & pos , & buf );
543+ if (r < 0 )
544+ goto err ;
538545 }
539546 if (t == TVAR ) {
540547 r = parse (& pos , & fmt [n ], NULL , NULL , NULL , NULL );
@@ -583,12 +590,14 @@ xbps_fmts(const char *format, xbps_fmt_cb *cb, void *data, FILE *fp)
583590 for (;;) {
584591 enum tok t ;
585592
586- t = nexttok (& pos , & buf );
587- if (t = = 0 )
593+ r = nexttok (& t , & pos , & buf );
594+ if (r < = 0 )
588595 goto out ;
589596 if (t == TTEXT ) {
590597 fprintf (fp , "%s" , buf .mem );
591- t = nexttok (& pos , & buf );
598+ r = nexttok (& t , & pos , & buf );
599+ if (r <= 0 )
600+ goto out ;
592601 }
593602 if (t == TVAR ) {
594603 struct xbps_fmt_def def = {0 };
0 commit comments