Print this page
6645 sgsmsg relies on undefined behaviour of loop-scoped variables


 648         if (column == 1)
 649                 fmtstr = "\n\t0x%.2x };\n";
 650         else
 651                 fmtstr = "  0x%.2x };\n";
 652 
 653         if (fprintf(fddata, fmtstr, (unsigned char)stbuf[stbufsize - 1]) < 0) {
 654                 (void) fprintf(stderr, Errmsg_wrte, fldata, strerror(errno));
 655                 return (1);
 656         }
 657 
 658         return (0);
 659 }
 660 
 661 static int
 662 file()
 663 {
 664         char    buffer[LINE_MAX], * token;
 665         uint_t  bufsize;
 666         char    *token_buffer;
 667         int     escape = 0;

 668 
 669         if ((token_buffer = malloc(LINE_MAX)) == 0) {
 670                 (void) fprintf(stderr, Errmsg_nmem, strerror(errno));
 671                 return (1);
 672         }
 673         bufsize = LINE_MAX;
 674 
 675         line = 1;
 676 
 677         while ((token = fgets(buffer, LINE_MAX, fddesc)) != NULL) {
 678                 char    defn[PATH_MAX], * _defn, * str;
 679                 int     len;
 680 
 681                 switch (*token) {
 682                 case '#':
 683                 case '$':
 684                         if (escape) {
 685                                 (void) fprintf(stderr, Errmsg_malt, fldesc,
 686                                     line);
 687                                 return (1);
 688                         }
 689 
 690                         /*
 691                          * If a msgid has been output a msgstr must follow
 692                          * before we digest the new token.  A msgid is only set
 693                          * if fdmsgs is in use.
 694                          */
 695                         if (msgid) {
 696                                 msgid = 0;
 697                                 if (fprintf(fdmsgs, "msgstr\t\"\"\n") < 0) {
 698                                         (void) fprintf(stderr, Errmsg_wrte,
 699                                             flmsgs, strerror(errno));




 648         if (column == 1)
 649                 fmtstr = "\n\t0x%.2x };\n";
 650         else
 651                 fmtstr = "  0x%.2x };\n";
 652 
 653         if (fprintf(fddata, fmtstr, (unsigned char)stbuf[stbufsize - 1]) < 0) {
 654                 (void) fprintf(stderr, Errmsg_wrte, fldata, strerror(errno));
 655                 return (1);
 656         }
 657 
 658         return (0);
 659 }
 660 
 661 static int
 662 file()
 663 {
 664         char    buffer[LINE_MAX], * token;
 665         uint_t  bufsize;
 666         char    *token_buffer;
 667         int     escape = 0;
 668         int     len = 0;
 669 
 670         if ((token_buffer = malloc(LINE_MAX)) == 0) {
 671                 (void) fprintf(stderr, Errmsg_nmem, strerror(errno));
 672                 return (1);
 673         }
 674         bufsize = LINE_MAX;
 675 
 676         line = 1;
 677 
 678         while ((token = fgets(buffer, LINE_MAX, fddesc)) != NULL) {
 679                 char    defn[PATH_MAX], * _defn, * str;

 680 
 681                 switch (*token) {
 682                 case '#':
 683                 case '$':
 684                         if (escape) {
 685                                 (void) fprintf(stderr, Errmsg_malt, fldesc,
 686                                     line);
 687                                 return (1);
 688                         }
 689 
 690                         /*
 691                          * If a msgid has been output a msgstr must follow
 692                          * before we digest the new token.  A msgid is only set
 693                          * if fdmsgs is in use.
 694                          */
 695                         if (msgid) {
 696                                 msgid = 0;
 697                                 if (fprintf(fdmsgs, "msgstr\t\"\"\n") < 0) {
 698                                         (void) fprintf(stderr, Errmsg_wrte,
 699                                             flmsgs, strerror(errno));