tools/nolibc: clean up sbrk() routine
authorZhangjin Wu <falcon@tinylab.org>
Fri, 7 Jul 2023 14:59:53 +0000 (22:59 +0800)
committerWilly Tarreau <w@1wt.eu>
Wed, 23 Aug 2023 02:38:02 +0000 (04:38 +0200)
Fix up the error reported by scripts/checkpatch.pl:

    ERROR: do not use assignment in if condition
    #95: FILE: tools/include/nolibc/sys.h:95:
    + if ((ret = sys_brk(0)) && (sys_brk(ret + inc) == ret + inc))

Apply the new generic __sysret() to merge the SET_ERRNO() and return
lines.

Signed-off-by: Zhangjin Wu <falcon@tinylab.org>
Signed-off-by: Willy Tarreau <w@1wt.eu>
tools/include/nolibc/sys.h

index 3d01a24..61a3204 100644 (file)
@@ -89,14 +89,13 @@ int brk(void *addr)
 static __attribute__((unused))
 void *sbrk(intptr_t inc)
 {
-       void *ret;
-
        /* first call to find current end */
-       if ((ret = sys_brk(0)) && (sys_brk(ret + inc) == ret + inc))
+       void *ret = sys_brk(0);
+
+       if (ret && sys_brk(ret + inc) == ret + inc)
                return ret + inc;
 
-       SET_ERRNO(ENOMEM);
-       return (void *)-1;
+       return (void *)__sysret(-ENOMEM);
 }