[hackers] [9base] replaced sbrk() uses with malloc() || Anselm R Garbe

From: <git_AT_suckless.org>
Date: Sun, 6 Aug 2017 09:30:49 +0200 (CEST)

commit 09e95a2d6f8dbafc6601147b2f5f150355813be6
Author: Anselm R Garbe <anselm_AT_garbe.us>
AuthorDate: Sun Aug 6 09:30:30 2017 +0200
Commit: Anselm R Garbe <anselm_AT_garbe.us>
CommitDate: Sun Aug 6 09:30:30 2017 +0200

    replaced sbrk() uses with malloc()

diff --git a/dd/dd.c b/dd/dd.c
index 1559914..9e69b6b 100644
--- a/dd/dd.c
+++ b/dd/dd.c
_AT_@ -203,13 +203,12 @@ main(int argc, char *argv[])
                 fprint(2, "dd: counts: cannot be zero\n");
                 exits("counts");
         }
- ibuf = sbrk(ibs);
+ ibuf = malloc(ibs);
         if(fflag)
                 obuf = ibuf;
         else
- obuf = sbrk(obs);
- sbrk(64); /* For good measure */
- if(ibuf == (char *)-1 || obuf == (char *)-1) {
+ obuf = malloc(obs);
+ if(ibuf == NULL || obuf == NULL) {
                 fprint(2, "dd: not enough memory: %r\n");
                 exits("memory");
         }
diff --git a/grep/sub.c b/grep/sub.c
index 5ea07c0..49c0988 100644
--- a/grep/sub.c
+++ b/grep/sub.c
_AT_@ -3,24 +3,27 @@
 void*
 mal(int n)
 {
- static char *s;
+ static char *s = NULL;
         static int m = 0;
- void *v;
+ void *v = NULL;
 
         n = (n+3) & ~3;
         if(m < n) {
                 if(n > Nhunk) {
- v = sbrk(n);
- memset(v, 0, n);
+ v = malloc(n);
+ if(v != NULL)
+ memset(v, 0, n);
                         return v;
                 }
- s = sbrk(Nhunk);
+ s = malloc(Nhunk);
                 m = Nhunk;
         }
         v = s;
- s += n;
+ if(s != NULL)
+ s += n;
         m -= n;
- memset(v, 0, n);
+ if(v != NULL)
+ memset(v, 0, n);
         return v;
 }
 
diff --git a/lib9/libc.h b/lib9/libc.h
index 66936e2..4a4c8ce 100644
--- a/lib9/libc.h
+++ b/lib9/libc.h
_AT_@ -782,7 +782,6 @@ extern long read(int, void*, long);
 extern long readn(int, void*, long);
 /* extern long readv(int, IOchunk*, int); <unistd.h> */
 extern int remove(const char*);
-/* extern void* sbrk(ulong); <unistd.h> */
 /* extern long oseek(int, long, int); */
 extern vlong p9seek(int, vlong, int);
 /* give up
Received on Sun Aug 06 2017 - 09:30:49 CEST

This archive was generated by hypermail 2.3.0 : Sun Aug 06 2017 - 09:36:52 CEST