]> git.pld-linux.org Git - packages/vim.git/blob - 7.3.152
- new
[packages/vim.git] / 7.3.152
1 To: vim_dev@googlegroups.com
2 Subject: Patch 7.3.152
3 Fcc: outbox
4 From: Bram Moolenaar <Bram@moolenaar.net>
5 Mime-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8 ------------
9
10 Patch 7.3.152
11 Problem:    Xxd does not check for errors from library functions.
12 Solution:   Add error checks. (Florian Zumbiehl)
13 Files:      src/xxd/xxd.c
14
15
16 *** ../vim-7.3.151/src/xxd/xxd.c        2010-08-15 21:57:25.000000000 +0200
17 --- src/xxd/xxd.c       2011-04-01 18:56:11.000000000 +0200
18 ***************
19 *** 49,54 ****
20 --- 49,56 ----
21    *        option -b added: 01000101 binary output in normal format.
22    * 16.05.00 Added VAXC changes by Stephen P. Wall
23    * 16.05.00 Improved MMS file and merge for VMS by Zoltan Arpadffy
24 +  * 2011 March  Better error handling by Florian Zumbiehl.
25 +  * 2011 April  Formatting by Bram Moolenaar
26    *
27    * (c) 1990-1998 by Juergen Weigert (jnweiger@informatik.uni-erlangen.de)
28    *
29 ***************
30 *** 207,214 ****
31   
32   /* Let's collect some prototypes */
33   /* CodeWarrior is really picky about missing prototypes */
34 ! static void exit_with_usage __P((char *));
35 ! static int huntype __P((FILE *, FILE *, FILE *, char *, int, int, long));
36   static void xxdline __P((FILE *, char *, int));
37   
38   #define TRY_SEEK      /* attempt to use lseek, or skip forward by reading */
39 --- 209,216 ----
40   
41   /* Let's collect some prototypes */
42   /* CodeWarrior is really picky about missing prototypes */
43 ! static void exit_with_usage __P((void));
44 ! static int huntype __P((FILE *, FILE *, FILE *, int, int, long));
45   static void xxdline __P((FILE *, char *, int));
46   
47   #define TRY_SEEK      /* attempt to use lseek, or skip forward by reading */
48 ***************
49 *** 223,231 ****
50   #define HEX_CINCLUDE 2
51   #define HEX_BITS 3            /* not hex a dump, but bits: 01111001 */
52   
53 ! static void
54 ! exit_with_usage(pname)
55 ! char *pname;
56   {
57     fprintf(stderr, "Usage:\n       %s [options] [infile [outfile]]\n", pname);
58     fprintf(stderr, "    or\n       %s -r [-s [-]offset] [-c cols] [-ps] [infile [outfile]]\n", pname);
59 --- 225,234 ----
60   #define HEX_CINCLUDE 2
61   #define HEX_BITS 3            /* not hex a dump, but bits: 01111001 */
62   
63 ! static char *pname;
64
65 !   static void
66 ! exit_with_usage()
67   {
68     fprintf(stderr, "Usage:\n       %s [options] [infile [outfile]]\n", pname);
69     fprintf(stderr, "    or\n       %s -r [-s [-]offset] [-c cols] [-ps] [infile [outfile]]\n", pname);
70 ***************
71 *** 252,257 ****
72 --- 255,269 ----
73     exit(1);
74   }
75   
76 +   static void
77 + die(ret)
78 +   int ret;
79 + {
80 +   fprintf(stderr, "%s: ", pname);
81 +   perror(NULL);
82 +   exit(ret);
83 + }
84
85   /*
86    * Max. cols binary characters are decoded from the input stream per line.
87    * Two adjacent garbage characters after evaluated data delimit valid data.
88 ***************
89 *** 259,270 ****
90    *
91    * The name is historic and came from 'undo type opt h'.
92    */
93 ! static int
94 ! huntype(fpi, fpo, fperr, pname, cols, hextype, base_off)
95 ! FILE *fpi, *fpo, *fperr;
96 ! char *pname;
97 ! int cols, hextype;
98 ! long base_off;
99   {
100     int c, ign_garb = 1, n1 = -1, n2 = 0, n3, p = cols;
101     long have_off = 0, want_off = 0;
102 --- 271,281 ----
103    *
104    * The name is historic and came from 'undo type opt h'.
105    */
106 !   static int
107 ! huntype(fpi, fpo, fperr, cols, hextype, base_off)
108 !   FILE *fpi, *fpo, *fperr;
109 !   int cols, hextype;
110 !   long base_off;
111   {
112     int c, ign_garb = 1, n1 = -1, n2 = 0, n3, p = cols;
113     long have_off = 0, want_off = 0;
114 ***************
115 *** 318,324 ****
116   
117         if (base_off + want_off != have_off)
118         {
119 !         fflush(fpo);
120   #ifdef TRY_SEEK
121           c = fseek(fpo, base_off + want_off - have_off, 1);
122           if (c >= 0)
123 --- 329,336 ----
124   
125         if (base_off + want_off != have_off)
126         {
127 !         if (fflush(fpo) != 0)
128 !           die(3);
129   #ifdef TRY_SEEK
130           c = fseek(fpo, base_off + want_off - have_off, 1);
131           if (c >= 0)
132 ***************
133 *** 330,341 ****
134               return 5;
135             }
136           for (; have_off < base_off + want_off; have_off++)
137 !           putc(0, fpo);
138         }
139   
140         if (n2 >= 0 && n1 >= 0)
141         {
142 !         putc((n2 << 4) | n1, fpo);
143           have_off++;
144           want_off++;
145           n1 = -1;
146 --- 342,355 ----
147               return 5;
148             }
149           for (; have_off < base_off + want_off; have_off++)
150 !           if (putc(0, fpo) == EOF)
151 !             die(3);
152         }
153   
154         if (n2 >= 0 && n1 >= 0)
155         {
156 !         if (putc((n2 << 4) | n1, fpo) == EOF)
157 !           die(3);
158           have_off++;
159           want_off++;
160           n1 = -1;
161 ***************
162 *** 345,350 ****
163 --- 359,366 ----
164               want_off = 0;
165               while ((c = getc(fpi)) != '\n' && c != EOF)
166                 ;
167 +             if (c == EOF && ferror(fpi))
168 +               die(2);
169               ign_garb = 1;
170             }
171         }
172 ***************
173 *** 355,369 ****
174             want_off = 0;
175           while ((c = getc(fpi)) != '\n' && c != EOF)
176             ;
177           ign_garb = 1;
178         }
179       }
180 !   fflush(fpo);
181   #ifdef TRY_SEEK
182     fseek(fpo, 0L, 2);
183   #endif
184 !   fclose(fpo);
185 !   fclose(fpi);
186     return 0;
187   }
188   
189 --- 371,390 ----
190             want_off = 0;
191           while ((c = getc(fpi)) != '\n' && c != EOF)
192             ;
193 +         if (c == EOF && ferror(fpi))
194 +           die(2);
195           ign_garb = 1;
196         }
197       }
198 !   if (fflush(fpo) != 0)
199 !     die(3);
200   #ifdef TRY_SEEK
201     fseek(fpo, 0L, 2);
202   #endif
203 !   if (fclose(fpo) != 0)
204 !     die(3);
205 !   if (fclose(fpi) != 0)
206 !     die(2);
207     return 0;
208   }
209   
210 ***************
211 *** 379,389 ****
212    *
213    * If nz is always positive, lines are never suppressed.
214    */
215 ! static void
216   xxdline(fp, l, nz)
217 ! FILE *fp;
218 ! char *l;
219 ! int nz;
220   {
221     static char z[LLEN+1];
222     static int zero_seen = 0;
223 --- 400,410 ----
224    *
225    * If nz is always positive, lines are never suppressed.
226    */
227 !   static void
228   xxdline(fp, l, nz)
229 !   FILE *fp;
230 !   char *l;
231 !   int nz;
232   {
233     static char z[LLEN+1];
234     static int zero_seen = 0;
235 ***************
236 *** 398,409 ****
237           if (nz < 0)
238             zero_seen--;
239           if (zero_seen == 2)
240 !           fputs(z, fp);
241           if (zero_seen > 2)
242 !           fputs("*\n", fp);
243         }
244         if (nz >= 0 || zero_seen > 0)
245 !       fputs(l, fp);
246         if (nz)
247         zero_seen = 0;
248       }
249 --- 419,433 ----
250           if (nz < 0)
251             zero_seen--;
252           if (zero_seen == 2)
253 !           if (fputs(z, fp) == EOF)
254 !             die(3);
255           if (zero_seen > 2)
256 !           if (fputs("*\n", fp) == EOF)
257 !             die(3);
258         }
259         if (nz >= 0 || zero_seen > 0)
260 !       if (fputs(l, fp) == EOF)
261 !         die(3);
262         if (nz)
263         zero_seen = 0;
264       }
265 ***************
266 *** 439,448 ****
267       0070,0071,0372,0373,0374,0375,0376,0377
268   };
269   
270 ! int
271   main(argc, argv)
272 ! int argc;
273 ! char *argv[];
274   {
275     FILE *fp, *fpo;
276     int c, e, p = 0, relseek = 1, negseek = 0, revert = 0;
277 --- 463,472 ----
278       0070,0071,0372,0373,0374,0375,0376,0377
279   };
280   
281 !   int
282   main(argc, argv)
283 !   int argc;
284 !   char *argv[];
285   {
286     FILE *fp, *fpo;
287     int c, e, p = 0, relseek = 1, negseek = 0, revert = 0;
288 ***************
289 *** 452,458 ****
290     int grplen;         /* total chars per octet group */
291     long length = -1, n = 0, seekoff = 0;
292     char l[LLEN+1];
293 !   char *pname, *pp;
294   
295   #ifdef AMIGA
296     /* This program doesn't work when started from the Workbench */
297 --- 476,482 ----
298     int grplen;         /* total chars per octet group */
299     long length = -1, n = 0, seekoff = 0;
300     char l[LLEN+1];
301 !   char *pp;
302   
303   #ifdef AMIGA
304     /* This program doesn't work when started from the Workbench */
305 ***************
306 *** 495,501 ****
307           else
308             {
309               if (!argv[2])
310 !               exit_with_usage(pname);
311               cols = (int)strtol(argv[2], NULL, 0);
312               argv++;
313               argc--;
314 --- 519,525 ----
315           else
316             {
317               if (!argv[2])
318 !               exit_with_usage();
319               cols = (int)strtol(argv[2], NULL, 0);
320               argv++;
321               argc--;
322 ***************
323 *** 508,514 ****
324           else
325             {
326               if (!argv[2])
327 !               exit_with_usage(pname);
328               octspergrp = (int)strtol(argv[2], NULL, 0);
329               argv++;
330               argc--;
331 --- 532,538 ----
332           else
333             {
334               if (!argv[2])
335 !               exit_with_usage();
336               octspergrp = (int)strtol(argv[2], NULL, 0);
337               argv++;
338               argc--;
339 ***************
340 *** 531,537 ****
341           else
342             {
343               if (!argv[2])
344 !               exit_with_usage(pname);
345   #ifdef TRY_SEEK
346               if (argv[2][0] == '+')
347                 relseek++;
348 --- 555,561 ----
349           else
350             {
351               if (!argv[2])
352 !               exit_with_usage();
353   #ifdef TRY_SEEK
354               if (argv[2][0] == '+')
355                 relseek++;
356 ***************
357 *** 550,556 ****
358           else
359             {
360               if (!argv[2])
361 !               exit_with_usage(pname);
362               length = strtol(argv[2], (char **)NULL, 0);
363               argv++;
364               argc--;
365 --- 574,580 ----
366           else
367             {
368               if (!argv[2])
369 !               exit_with_usage();
370               length = strtol(argv[2], (char **)NULL, 0);
371               argv++;
372               argc--;
373 ***************
374 *** 563,569 ****
375           break;
376         }
377         else if (pp[0] == '-' && pp[1]) /* unknown option */
378 !       exit_with_usage(pname);
379         else
380         break;                          /* not an option */
381   
382 --- 587,593 ----
383           break;
384         }
385         else if (pp[0] == '-' && pp[1]) /* unknown option */
386 !       exit_with_usage();
387         else
388         break;                          /* not an option */
389   
390 ***************
391 *** 602,608 ****
392       octspergrp = cols;
393   
394     if (argc > 3)
395 !     exit_with_usage(pname);
396   
397     if (argc == 1 || (argv[1][0] == '-' && !argv[1][1]))
398       BIN_ASSIGN(fp = stdin, !revert);
399 --- 626,632 ----
400       octspergrp = cols;
401   
402     if (argc > 3)
403 !     exit_with_usage();
404   
405     if (argc == 1 || (argv[1][0] == '-' && !argv[1][1]))
406       BIN_ASSIGN(fp = stdin, !revert);
407 ***************
408 *** 640,646 ****
409           fprintf(stderr, "%s: sorry, cannot revert this type of hexdump\n", pname);
410           return -1;
411         }
412 !       return huntype(fp, fpo, stderr, pname, cols, hextype,
413                 negseek ? -seekoff : seekoff);
414       }
415   
416 --- 664,670 ----
417           fprintf(stderr, "%s: sorry, cannot revert this type of hexdump\n", pname);
418           return -1;
419         }
420 !       return huntype(fp, fpo, stderr, cols, hextype,
421                 negseek ? -seekoff : seekoff);
422       }
423   
424 ***************
425 *** 664,670 ****
426           long s = seekoff;
427   
428           while (s--)
429 !           (void)getc(fp);
430         }
431       }
432   
433 --- 688,703 ----
434           long s = seekoff;
435   
436           while (s--)
437 !           if (getc(fp) == EOF)
438 !             if (ferror(fp))
439 !               {
440 !                 die(2);
441 !               }
442 !             else
443 !               {
444 !                 fprintf(stderr, "%s: sorry cannot seek.\n", pname);
445 !                 return 4;
446 !               }
447         }
448       }
449   
450 ***************
451 *** 672,725 ****
452       {
453         if (fp != stdin)
454         {
455 !         fprintf(fpo, "unsigned char %s", isdigit((int)argv[1][0]) ? "__" : "");
456           for (e = 0; (c = argv[1][e]) != 0; e++)
457 !           putc(isalnum(c) ? c : '_', fpo);
458 !         fputs("[] = {\n", fpo);
459         }
460   
461         p = 0;
462         while ((length < 0 || p < length) && (c = getc(fp)) != EOF)
463         {
464 !         fprintf(fpo, (hexx == hexxa) ? "%s0x%02x" : "%s0X%02X",
465 !           (p % cols) ? ", " : ",\n  "+2*!p,  c);
466           p++;
467         }
468   
469         if (p)
470 !       fputs("\n};\n"+3*(fp == stdin), fpo);
471   
472         if (fp != stdin)
473         {
474 !         fprintf(fpo, "unsigned int %s", isdigit((int)argv[1][0]) ? "__" : "");
475           for (e = 0; (c = argv[1][e]) != 0; e++)
476 !           putc(isalnum(c) ? c : '_', fpo);
477 !         fprintf(fpo, "_len = %d;\n", p);
478         }
479   
480 !       fclose(fp);
481 !       fclose(fpo);
482         return 0;
483       }
484   
485     if (hextype == HEX_POSTSCRIPT)
486       {
487         p = cols;
488         while ((length < 0 || n < length) && (e = getc(fp)) != EOF)
489         {
490 !         putchar(hexx[(e >> 4) & 0xf]);
491 !         putchar(hexx[(e     ) & 0xf]);
492           n++;
493           if (!--p)
494             {
495 !             putchar('\n');
496               p = cols;
497             }
498         }
499         if (p < cols)
500 !       putchar('\n');
501 !       fclose(fp);
502 !       fclose(fpo);
503         return 0;
504       }
505   
506 --- 705,779 ----
507       {
508         if (fp != stdin)
509         {
510 !         if (fprintf(fpo, "unsigned char %s", isdigit((int)argv[1][0]) ? "__" : "") < 0)
511 !           die(3);
512           for (e = 0; (c = argv[1][e]) != 0; e++)
513 !           if (putc(isalnum(c) ? c : '_', fpo) == EOF)
514 !             die(3);
515 !         if (fputs("[] = {\n", fpo) == EOF)
516 !           die(3);
517         }
518   
519         p = 0;
520 +       c = 0;
521         while ((length < 0 || p < length) && (c = getc(fp)) != EOF)
522         {
523 !         if (fprintf(fpo, (hexx == hexxa) ? "%s0x%02x" : "%s0X%02X",
524 !               (p % cols) ? ", " : ",\n  "+2*!p,  c) < 0)
525 !           die(3);
526           p++;
527         }
528 +       if (c == EOF && ferror(fp))
529 +       die(2);
530   
531         if (p)
532 !       if (fputs("\n};\n" + 3 * (fp == stdin), fpo) == EOF)
533 !         die(3);
534   
535         if (fp != stdin)
536         {
537 !         if (fprintf(fpo, "unsigned int %s", isdigit((int)argv[1][0]) ? "__" : "") < 0)
538 !           die(3);
539           for (e = 0; (c = argv[1][e]) != 0; e++)
540 !           if (putc(isalnum(c) ? c : '_', fpo) == EOF)
541 !             die(3);
542 !         if (fprintf(fpo, "_len = %d;\n", p) < 0)
543 !           die(3);
544         }
545   
546 !       if (fclose(fp))
547 !       die(2);
548 !       if (fclose(fpo))
549 !       die(3);
550         return 0;
551       }
552   
553     if (hextype == HEX_POSTSCRIPT)
554       {
555         p = cols;
556 +       e = 0;
557         while ((length < 0 || n < length) && (e = getc(fp)) != EOF)
558         {
559 !         if (putc(hexx[(e >> 4) & 0xf], fpo) == EOF
560 !                 || putc(hexx[e & 0xf], fpo) == EOF)
561 !           die(3);
562           n++;
563           if (!--p)
564             {
565 !             if (putc('\n', fpo) == EOF)
566 !               die(3);
567               p = cols;
568             }
569         }
570 +       if (e == EOF && ferror(fp))
571 +       die(2);
572         if (p < cols)
573 !       if (putc('\n', fpo) == EOF)
574 !         die(3);
575 !       if (fclose(fp))
576 !       die(2);
577 !       if (fclose(fpo))
578 !       die(3);
579         return 0;
580       }
581   
582 ***************
583 *** 730,735 ****
584 --- 784,790 ----
585     else        /* hextype == HEX_BITS */
586       grplen = 8 * octspergrp + 1;
587   
588 +   e = 0;
589     while ((length < 0 || n < length) && (e = getc(fp)) != EOF)
590       {
591         if (p == 0)
592 ***************
593 *** 771,776 ****
594 --- 826,833 ----
595           p = 0;
596         }
597       }
598 +   if (e == EOF && ferror(fp))
599 +     die(2);
600     if (p)
601       {
602         l[c = (11 + (grplen * cols - 1)/octspergrp + p)] = '\n'; l[++c] = '\0';
603 ***************
604 *** 779,785 ****
605     else if (autoskip)
606       xxdline(fpo, l, -1);      /* last chance to flush out suppressed lines */
607   
608 !   fclose(fp);
609 !   fclose(fpo);
610     return 0;
611   }
612 --- 836,846 ----
613     else if (autoskip)
614       xxdline(fpo, l, -1);      /* last chance to flush out suppressed lines */
615   
616 !   if (fclose(fp))
617 !     die(2);
618 !   if (fclose(fpo))
619 !     die(3);
620     return 0;
621   }
622
623 + /* vi:set ts=8 sw=4 sts=2 cino+={2 cino+=n-2 : */
624 *** ../vim-7.3.151/src/version.c        2011-04-01 16:28:33.000000000 +0200
625 --- src/version.c       2011-04-01 19:00:26.000000000 +0200
626 ***************
627 *** 716,717 ****
628 --- 716,719 ----
629   {   /* Add new patch number below this line */
630 + /**/
631 +     152,
632   /**/
633
634 -- 
635 Eye have a spelling checker, it came with my PC;
636 It plainly marks four my revue mistakes I cannot sea.
637 I've run this poem threw it, I'm sure your please to no,
638 It's letter perfect in it's weigh, my checker tolled me sew!
639
640  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
641 ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
642 \\\  an exciting new programming language -- http://www.Zimbu.org        ///
643  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
This page took 0.076715 seconds and 3 git commands to generate.