commit 09e95a2d6f8dbafc6601147b2f5f150355813be6
Author:     Anselm R Garbe <ans...@garbe.us>
AuthorDate: Sun Aug 6 09:30:30 2017 +0200
Commit:     Anselm R Garbe <ans...@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
@@ -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
@@ -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
@@ -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

Reply via email to