projects
/
u
/
mdw
/
putty
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
More portability fixes.
[u/mdw/putty]
/
misc.c
diff --git
a/misc.c
b/misc.c
index
8edb41a
..
09e6db5
100644
(file)
--- a/
misc.c
+++ b/
misc.c
@@
-11,9
+11,12
@@
char *dupstr(const char *s)
{
char *dupstr(const char *s)
{
- int len = strlen(s);
- char *p = smalloc(len + 1);
- strcpy(p, s);
+ char *p = NULL;
+ if (s) {
+ int len = strlen(s);
+ p = snewn(len + 1, char);
+ strcpy(p, s);
+ }
return p;
}
return p;
}
@@
-34,7
+37,7
@@
char *dupcat(const char *s1, ...)
}
va_end(ap);
}
va_end(ap);
- p = s
malloc(len + 1
);
+ p = s
newn(len + 1, char
);
strcpy(p, s1);
q = p + strlen(p);
strcpy(p, s1);
q = p + strlen(p);
@@
-76,7
+79,7
@@
char *dupvprintf(const char *fmt, va_list ap)
char *buf;
int len, size;
char *buf;
int len, size;
- buf = s
malloc(512
);
+ buf = s
newn(512, char
);
size = 512;
while (1) {
size = 512;
while (1) {
@@
-97,7
+100,7
@@
char *dupvprintf(const char *fmt, va_list ap)
* buffer wasn't big enough, so we enlarge it a bit and hope. */
size += 512;
}
* buffer wasn't big enough, so we enlarge it a bit and hope. */
size += 512;
}
- buf = sre
alloc(buf, size
);
+ buf = sre
size(buf, size, char
);
}
}
}
}
@@
-178,6
+181,8
@@
void bufchain_add(bufchain *ch, const void *data, int len)
{
const char *buf = (const char *)data;
{
const char *buf = (const char *)data;
+ if (len == 0) return;
+
ch->buffersize += len;
if (ch->tail && ch->tail->buflen < BUFFER_GRANULE) {
ch->buffersize += len;
if (ch->tail && ch->tail->buflen < BUFFER_GRANULE) {
@@
-190,7
+195,7
@@
void bufchain_add(bufchain *ch, const void *data, int len)
while (len > 0) {
int grainlen = min(len, BUFFER_GRANULE);
struct bufchain_granule *newbuf;
while (len > 0) {
int grainlen = min(len, BUFFER_GRANULE);
struct bufchain_granule *newbuf;
- newbuf = s
malloc(sizeof(struct bufchain_granule)
);
+ newbuf = s
new(struct bufchain_granule
);
newbuf->bufpos = 0;
newbuf->buflen = grainlen;
memcpy(newbuf->buf, buf, grainlen);
newbuf->bufpos = 0;
newbuf->buflen = grainlen;
memcpy(newbuf->buf, buf, grainlen);