abuild: avoid calculations with void pointers
Arithmetic operations with void pointers are an extension by some compilers and not part of the C standard, which does not specify the size of void. CFLAGS with -pedantic reveals this during compile time. I have adjusted the usage of ?: so CFLAGS can contain -pedantic now.
This commit is contained in:
parent
0db2d3397a
commit
f2ab775123
2
Makefile
2
Makefile
|
@ -34,7 +34,7 @@ TAR := tar
|
||||||
SCDOC := scdoc
|
SCDOC := scdoc
|
||||||
LINK = $(CC) $(OBJS-$@) -o $@ $(LDFLAGS) $(LDFLAGS-$@) $(LIBS-$@)
|
LINK = $(CC) $(OBJS-$@) -o $@ $(LDFLAGS) $(LDFLAGS-$@) $(LIBS-$@)
|
||||||
|
|
||||||
CFLAGS ?= -Wall -Werror -g
|
CFLAGS ?= -Wall -Werror -g -pedantic
|
||||||
|
|
||||||
SED_REPLACE := -e 's:@VERSION@:$(FULL_VERSION):g' \
|
SED_REPLACE := -e 's:@VERSION@:$(FULL_VERSION):g' \
|
||||||
-e 's:@prefix@:$(prefix):g' \
|
-e 's:@prefix@:$(prefix):g' \
|
||||||
|
|
|
@ -75,7 +75,7 @@ int main(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (zs.avail_in == 0 || r == Z_STREAM_END) {
|
if (zs.avail_in == 0 || r == Z_STREAM_END) {
|
||||||
len = (void *)zs.next_in - (void *)ibuf;
|
len = (char *)zs.next_in - (char *)ibuf;
|
||||||
if (write(fd, ibuf, len) != len) {
|
if (write(fd, ibuf, len) != len) {
|
||||||
warn("Failed to write to %s", fn);
|
warn("Failed to write to %s", fn);
|
||||||
goto err;
|
goto err;
|
||||||
|
|
|
@ -104,7 +104,7 @@ int main(int argc, const char *argv[])
|
||||||
|
|
||||||
if (name == NULL)
|
if (name == NULL)
|
||||||
warnx("Could not find username for uid %d\n", uid);
|
warnx("Could not find username for uid %d\n", uid);
|
||||||
setenv("USER", name ?: "", 1);
|
setenv("USER", name ? name : "", 1);
|
||||||
|
|
||||||
cmd = strrchr(argv[0], '/');
|
cmd = strrchr(argv[0], '/');
|
||||||
if (cmd)
|
if (cmd)
|
||||||
|
|
10
abuild-tar.c
10
abuild-tar.c
|
@ -122,15 +122,16 @@ static int usage(void)
|
||||||
static ssize_t full_read(int fd, void *buf, size_t count)
|
static ssize_t full_read(int fd, void *buf, size_t count)
|
||||||
{
|
{
|
||||||
ssize_t total, n;
|
ssize_t total, n;
|
||||||
|
char *p = buf;
|
||||||
|
|
||||||
total = 0;
|
total = 0;
|
||||||
do {
|
do {
|
||||||
n = read(fd, buf, count);
|
n = read(fd, p, count);
|
||||||
if (n < 0 && errno == EINTR)
|
if (n < 0 && errno == EINTR)
|
||||||
continue;
|
continue;
|
||||||
if (n <= 0)
|
if (n <= 0)
|
||||||
break;
|
break;
|
||||||
buf += n;
|
p += n;
|
||||||
total += n;
|
total += n;
|
||||||
count -= n;
|
count -= n;
|
||||||
} while (1);
|
} while (1);
|
||||||
|
@ -144,15 +145,16 @@ static ssize_t full_read(int fd, void *buf, size_t count)
|
||||||
static ssize_t full_write(int fd, const void *buf, size_t count)
|
static ssize_t full_write(int fd, const void *buf, size_t count)
|
||||||
{
|
{
|
||||||
ssize_t total, n;
|
ssize_t total, n;
|
||||||
|
const char *p = buf;
|
||||||
|
|
||||||
total = 0;
|
total = 0;
|
||||||
do {
|
do {
|
||||||
n = write(fd, buf, count);
|
n = write(fd, p, count);
|
||||||
if (n < 0 && errno == EINTR)
|
if (n < 0 && errno == EINTR)
|
||||||
continue;
|
continue;
|
||||||
if (n <= 0)
|
if (n <= 0)
|
||||||
break;
|
break;
|
||||||
buf += n;
|
p += n;
|
||||||
total += n;
|
total += n;
|
||||||
count -= n;
|
count -= n;
|
||||||
} while (1);
|
} while (1);
|
||||||
|
|
Loading…
Reference in New Issue