Hello everybody.
There it is a tiny diff about ed ...
1/ using a long long (for 32 bits case) for strtol.
2/ realloc => reallocarray
Hope it has any use....
Kind regards.
Index: ed.h
===================================================================
RCS file: /cvs/src/bin/ed/ed.h,v
retrieving revision 1.15
diff -u -p -r1.15 ed.h
--- ed.h 16 Jan 2015 06:39:32 -0000 1.15
+++ ed.h 29 Apr 2015 22:22:22 -0000
@@ -105,22 +105,26 @@ if (--mutex == 0) { \
/* STRTOI: convert a string to int */
#define STRTOI(i, p) { \
- long l = strtol(p, &p, 10); \
- if (l <= INT_MIN || l >= INT_MAX) { \
- seterrmsg("number out of range"); \
- i = 0; \
- return ERR; \
- } else \
- i = (int)l; \
+ long long l = strtol(p, &p, 10); \
+ if (l <= INT_MIN || l >= INT_MAX) { \
+ seterrmsg("number out of range"); \
+ i = 0; \
+ return ERR; \
+ } else \
+ i = (int)l; \
}
/* REALLOC: assure at least a minimum size for buffer b */
#define REALLOC(b,n,i,err) \
if ((i) > (n)) { \
- int ti = (n); \
+ size_t ti = (n) + max((i), MINBUFSZ); \
char *ts; \
SPL1(); \
- if ((ts = (char *) realloc((b), ti += max((i), MINBUFSZ))) == NULL) { \
+ if ((ts = reallocarray((b), ti, sizeof(char))) == NULL) { \
+ if ((b)) { \
+ free((b)); \
+ ((b)) = 0; \
+ } \
perror(NULL); \
seterrmsg("out of memory"); \
SPL0(); \