comparison buffer.c @ 70:b0316ce64e4b

Merging in the changes from 0.41-0.43 main Dropbear tree
author Matt Johnston <matt@ucc.asn.au>
date Thu, 12 Aug 2004 16:41:58 +0000
parents fe6bca95afa7
children 10f4d3319780
comparison
equal deleted inserted replaced
69:59d16db56e9f 70:b0316ce64e4b
32 * Calling functions should check arguments first, but this provides a 32 * Calling functions should check arguments first, but this provides a
33 * backstop */ 33 * backstop */
34 #define BUF_MAX_INCR 1000000000 34 #define BUF_MAX_INCR 1000000000
35 #define BUF_MAX_SIZE 1000000000 35 #define BUF_MAX_SIZE 1000000000
36 36
37 /* avoid excessively large numbers, > 5000 bit */ 37 /* avoid excessively large numbers, > ~8192 bits */
38 #define BUF_MAX_MPINT (5000 / 8) 38 #define BUF_MAX_MPINT (8240 / 8)
39 39
40 /* Create (malloc) a new buffer of size */ 40 /* Create (malloc) a new buffer of size */
41 buffer* buf_new(unsigned int size) { 41 buffer* buf_new(unsigned int size) {
42 42
43 buffer* buf; 43 buffer* buf;
74 74
75 m_burn(buf->data, buf->size); 75 m_burn(buf->data, buf->size);
76 76
77 } 77 }
78 78
79 /* resize a buffer, pos and len will be repositioned if required */ 79 /* resize a buffer, pos and len will be repositioned if required when
80 * downsizing */
80 void buf_resize(buffer *buf, unsigned int newsize) { 81 void buf_resize(buffer *buf, unsigned int newsize) {
81 82
82 if (newsize > BUF_MAX_SIZE) { 83 if (newsize > BUF_MAX_SIZE) {
83 dropbear_exit("buf->size too big"); 84 dropbear_exit("buf->size too big");
84 } 85 }
149 } 150 }
150 151
151 /* Get a byte from the buffer and increment the pos */ 152 /* Get a byte from the buffer and increment the pos */
152 unsigned char buf_getbyte(buffer* buf) { 153 unsigned char buf_getbyte(buffer* buf) {
153 154
155 /* This check is really just ==, but the >= allows us to check for the
156 * assert()able case of pos > len, which should _never_ happen. */
154 if (buf->pos >= buf->len) { 157 if (buf->pos >= buf->len) {
155 dropbear_exit("bad buf_getbyte"); 158 dropbear_exit("bad buf_getbyte");
156 } 159 }
157 return buf->data[buf->pos++]; 160 return buf->data[buf->pos++];
158 } 161 }