]> diplodocus.org Git - nmh/blob - sbr/seq_bits.c
Fix invalid pointer arithmetic.
[nmh] / sbr / seq_bits.c
1 /* seq_bits.c -- return the snprintb() string for a sequence
2 *
3 * This code is Copyright (c) 2002, by the authors of nmh. See the
4 * COPYRIGHT file in the root directory of the nmh distribution for
5 * complete copyright information.
6 */
7
8 #include <h/mh.h>
9
10
11 char *
12 seq_bits (struct msgs *mp)
13 {
14 size_t i;
15 size_t len;
16 static char buffer[BUFSIZ];
17
18 strncpy (buffer, MBITS, sizeof(buffer));
19
20 for (i = 0; i < svector_size (mp->msgattrs); i++) {
21 len = strlen (buffer);
22 snprintf (buffer + len, sizeof(buffer) - len,
23 "%c%s", FFATTRSLOT + 1 + (int) i,
24 svector_at (mp->msgattrs, i));
25 /*
26 * seq_bits() is used by seq_printdebug(), which passes an
27 * unsigned int bit vector to snprintb(). So limit the
28 * size of the return value accordingly. Even worse,
29 * snprintb() only uses characters up through ASCII space
30 * as the delimiter (the %c character above). So limit
31 * based on that.
32 */
33 if ((int) i == ' ' - FFATTRSLOT - 1) break;
34 }
35
36 return buffer;
37 }