Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 721566 | Differences between
and this patch

Collapse All | Expand All

(-)a/Makefile (-3 / +3 lines)
Lines 1673-1679 qsutil.h Link Here
1673
	./compile qsutil.c
1673
	./compile qsutil.c
1674
1674
1675
quote.o: \
1675
quote.o: \
1676
compile quote.c stralloc.h gen_alloc.h str.h quote.h
1676
compile quote.c stralloc.h gen_alloc.h str.h quote.h error.h
1677
	./compile quote.c
1677
	./compile quote.c
1678
1678
1679
rcpthosts.o: \
1679
rcpthosts.o: \
Lines 1965-1971 compile stralloc_cat.c byte.h stralloc.h gen_alloc.h Link Here
1965
	./compile stralloc_cat.c
1965
	./compile stralloc_cat.c
1966
1966
1967
stralloc_catb.o: \
1967
stralloc_catb.o: \
1968
compile stralloc_catb.c stralloc.h gen_alloc.h byte.h
1968
compile stralloc_catb.c stralloc.h gen_alloc.h byte.h error.h
1969
	./compile stralloc_catb.c
1969
	./compile stralloc_catb.c
1970
1970
1971
stralloc_cats.o: \
1971
stralloc_cats.o: \
Lines 1982-1988 gen_allocdefs.h Link Here
1982
	./compile stralloc_eady.c
1982
	./compile stralloc_eady.c
1983
1983
1984
stralloc_opyb.o: \
1984
stralloc_opyb.o: \
1985
compile stralloc_opyb.c stralloc.h gen_alloc.h byte.h
1985
compile stralloc_opyb.c stralloc.h gen_alloc.h byte.h error.h
1986
	./compile stralloc_opyb.c
1986
	./compile stralloc_opyb.c
1987
1987
1988
stralloc_opys.o: \
1988
stralloc_opys.o: \
(-)a/alloc.c (-7 / +14 lines)
Lines 1-7 Link Here
1
#include <stdlib.h>
1
#include "alloc.h"
2
#include "alloc.h"
2
#include "error.h"
3
#include "error.h"
3
extern char *malloc();
4
extern void free();
5
4
6
#define ALIGNMENT 16 /* XXX: assuming that this alignment is enough */
5
#define ALIGNMENT 16 /* XXX: assuming that this alignment is enough */
7
#define SPACE 4096 /* must be multiple of ALIGNMENT */
6
#define SPACE 4096 /* must be multiple of ALIGNMENT */
Lines 11-25 static aligned realspace[SPACE / ALIGNMENT]; Link Here
11
#define space ((char *) realspace)
10
#define space ((char *) realspace)
12
static unsigned int avail = SPACE; /* multiple of ALIGNMENT; 0<=avail<=SPACE */
11
static unsigned int avail = SPACE; /* multiple of ALIGNMENT; 0<=avail<=SPACE */
13
12
13
static char *m_alloc(unsigned int n)
14
{
15
  char *x = malloc(n);
16
  if (!x) errno = error_nomem;
17
  return x;
18
}
19
14
/*@null@*//*@out@*/char *alloc(n)
20
/*@null@*//*@out@*/char *alloc(n)
15
unsigned int n;
21
unsigned int n;
16
{
22
{
17
  char *x;
23
  if (n >= SPACE)
18
  n = ALIGNMENT + n - (n & (ALIGNMENT - 1)); /* XXX: could overflow */
24
    return m_alloc(n);
25
  /* Round it up to the next multiple of alignment. Could overflow if n is
26
   * close to 2**32, but by the check above this is already ruled out. */
27
  n = ALIGNMENT + n - (n & (ALIGNMENT - 1));
19
  if (n <= avail) { avail -= n; return space + avail; }
28
  if (n <= avail) { avail -= n; return space + avail; }
20
  x = malloc(n);
29
  return m_alloc(n);
21
  if (!x) errno = error_nomem;
22
  return x;
23
}
30
}
24
31
25
void alloc_free(x)
32
void alloc_free(x)
(-)a/qmail-local.c (-1 / +1 lines)
Lines 633-639 char **argv; Link Here
633
     i = j + 1;
633
     i = j + 1;
634
    }
634
    }
635
635
636
 recips = (char **) alloc((numforward + 1) * sizeof(char *));
636
 recips = (char **) calloc(numforward + 1, sizeof(char *));
637
 if (!recips) temp_nomem();
637
 if (!recips) temp_nomem();
638
 numforward = 0;
638
 numforward = 0;
639
639
(-)a/qmail-pop3d.c (-1 / +1 lines)
Lines 131-137 void getlist() Link Here
131
  if (maildir_scan(&pq,&filenames,1,1) == -1) die_scan();
131
  if (maildir_scan(&pq,&filenames,1,1) == -1) die_scan();
132
 
132
 
133
  numm = pq.p ? pq.len : 0;
133
  numm = pq.p ? pq.len : 0;
134
  m = (struct message *) alloc(numm * sizeof(struct message));
134
  m = (struct message *) calloc(numm, sizeof(struct message));
135
  if (!m) die_nomem();
135
  if (!m) die_nomem();
136
 
136
 
137
  for (i = 0;i < numm;++i) {
137
  for (i = 0;i < numm;++i) {
(-)a/quote.c (-1 / +9 lines)
Lines 1-3 Link Here
1
#include "error.h"
1
#include "stralloc.h"
2
#include "stralloc.h"
2
#include "str.h"
3
#include "str.h"
3
#include "quote.h"
4
#include "quote.h"
Lines 23-30 stralloc *sain; Link Here
23
 char ch;
24
 char ch;
24
 int i;
25
 int i;
25
 int j;
26
 int j;
27
 unsigned int nlen;
26
28
27
 if (!stralloc_ready(saout,sain->len * 2 + 2)) return 0;
29
 /* make sure the size calculation below does not overflow */
30
 if (__builtin_mul_overflow(sain->len, 2, &nlen) ||
31
     __builtin_add_overflow(nlen, 2, &nlen)) {
32
   errno = error_nomem;
33
   return 0;
34
 }
35
 if (!stralloc_ready(saout,nlen)) return 0;
28
 j = 0;
36
 j = 0;
29
 saout->s[j++] = '"';
37
 saout->s[j++] = '"';
30
 for (i = 0;i < sain->len;++i)
38
 for (i = 0;i < sain->len;++i)
(-)a/stralloc_catb.c (-1 / +7 lines)
Lines 1-13 Link Here
1
#include "stralloc.h"
1
#include "stralloc.h"
2
#include "byte.h"
2
#include "byte.h"
3
#include "error.h"
3
4
4
int stralloc_catb(sa,s,n)
5
int stralloc_catb(sa,s,n)
5
stralloc *sa;
6
stralloc *sa;
6
char *s;
7
char *s;
7
unsigned int n;
8
unsigned int n;
8
{
9
{
10
  unsigned int i;
9
  if (!sa->s) return stralloc_copyb(sa,s,n);
11
  if (!sa->s) return stralloc_copyb(sa,s,n);
10
  if (!stralloc_readyplus(sa,n + 1)) return 0;
12
  if (__builtin_add_overflow(n, 1, &i)) {
13
    errno = error_nomem;
14
    return 0;
15
  }
16
  if (!stralloc_readyplus(sa,i)) return 0;
11
  byte_copy(sa->s + sa->len,n,s);
17
  byte_copy(sa->s + sa->len,n,s);
12
  sa->len += n;
18
  sa->len += n;
13
  sa->s[sa->len] = 'Z'; /* ``offensive programming'' */
19
  sa->s[sa->len] = 'Z'; /* ``offensive programming'' */
(-)a/stralloc_opyb.c (-1 / +7 lines)
Lines 1-12 Link Here
1
#include "stralloc.h"
1
#include "stralloc.h"
2
#include "byte.h"
2
#include "byte.h"
3
#include "error.h"
3
4
4
int stralloc_copyb(sa,s,n)
5
int stralloc_copyb(sa,s,n)
5
stralloc *sa;
6
stralloc *sa;
6
char *s;
7
char *s;
7
unsigned int n;
8
unsigned int n;
8
{
9
{
9
  if (!stralloc_ready(sa,n + 1)) return 0;
10
  unsigned int i;
11
  if (__builtin_add_overflow(n, 1, &i)) {
12
    errno = error_nomem;
13
    return 0;
14
  }
15
  if (!stralloc_ready(sa,i)) return 0;
10
  byte_copy(sa->s,n,s);
16
  byte_copy(sa->s,n,s);
11
  sa->len = n;
17
  sa->len = n;
12
  sa->s[n] = 'Z'; /* ``offensive programming'' */
18
  sa->s[n] = 'Z'; /* ``offensive programming'' */
(-)a/substdo.c (-3 / +2 lines)
Lines 38-46 register substdio *s; Link Here
38
int substdio_bput(s,buf,len)
38
int substdio_bput(s,buf,len)
39
register substdio *s;
39
register substdio *s;
40
register char *buf;
40
register char *buf;
41
register int len;
41
register unsigned int len;
42
{
42
{
43
  register int n;
43
  register unsigned int n;
44
 
44
 
45
  while (len > (n = s->n - s->p)) {
45
  while (len > (n = s->n - s->p)) {
46
    byte_copy(s->x + s->p,n,buf); s->p += n; buf += n; len -= n;
46
    byte_copy(s->x + s->p,n,buf); s->p += n; buf += n; len -= n;
47
- 

Return to bug 721566