summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2012-01-21 04:01:56 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2012-01-21 04:01:56 +0100
commita47e6b9fbb98e2363af28cf9cfa436964faa4fc6 (patch)
tree56e7f9cb537f1ccb0c6a65f9797bae3ad63d9087
parent6cecba53225ae30f1a28ce6954fb0cda847f3688 (diff)
downloadstrace-a47e6b9fbb98e2363af28cf9cfa436964faa4fc6.tar.gz
Improve code readability (logic is unchanged)
* util.c (umoven): Move assignment out of function call. Make assignment to a flag variable later, closer to the place where it will be used. (umovestr): Likewise. (uload): Likewise. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--util.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/util.c b/util.c
index 64c1f8a05..d9ec1b3cf 100644
--- a/util.c
+++ b/util.c
@@ -780,7 +780,7 @@ umoven(struct tcb *tcp, long addr, int len, char *laddr)
#ifdef LINUX
int pid = tcp->pid;
int n, m;
- int started = 0;
+ int started;
union {
long val;
char x[sizeof(long)];
@@ -791,6 +791,7 @@ umoven(struct tcb *tcp, long addr, int len, char *laddr)
addr &= (1ul << 8 * personality_wordsize[current_personality]) - 1;
#endif
+ started = 0;
if (addr & (sizeof(long) - 1)) {
/* addr not a multiple of sizeof(long) */
n = addr - (addr & -sizeof(long)); /* residue */
@@ -804,7 +805,8 @@ umoven(struct tcb *tcp, long addr, int len, char *laddr)
return -1;
}
started = 1;
- memcpy(laddr, &u.x[n], m = MIN(sizeof(long) - n, len));
+ m = MIN(sizeof(long) - n, len);
+ memcpy(laddr, &u.x[n], m);
addr += sizeof(long), laddr += m, len -= m;
}
while (len) {
@@ -820,7 +822,8 @@ umoven(struct tcb *tcp, long addr, int len, char *laddr)
return -1;
}
started = 1;
- memcpy(laddr, u.x, m = MIN(sizeof(long), len));
+ m = MIN(sizeof(long), len);
+ memcpy(laddr, u.x, m);
addr += sizeof(long), laddr += m, len -= m;
}
#endif /* LINUX */
@@ -876,11 +879,11 @@ int
umovestr(struct tcb *tcp, long addr, int len, char *laddr)
{
#ifdef USE_PROCFS
-#ifdef HAVE_MP_PROCFS
+# ifdef HAVE_MP_PROCFS
int fd = tcp->pfd_as;
-#else
+# else
int fd = tcp->pfd;
-#endif
+# endif
/* Some systems (e.g. FreeBSD) can be upset if we read off the
end of valid memory, avoid this by trying to read up
to page boundaries. But we don't know what a page is (and
@@ -907,8 +910,9 @@ umovestr(struct tcb *tcp, long addr, int len, char *laddr)
addr += move;
move = page;
}
+ return 0;
#else /* !USE_PROCFS */
- int started = 0;
+ int started;
int pid = tcp->pid;
int i, n, m;
union {
@@ -921,6 +925,7 @@ umovestr(struct tcb *tcp, long addr, int len, char *laddr)
addr &= (1ul << 8 * personality_wordsize[current_personality]) - 1;
#endif
+ started = 0;
if (addr & (sizeof(long) - 1)) {
/* addr not a multiple of sizeof(long) */
n = addr - (addr & -sizeof(long)); /* residue */
@@ -933,7 +938,8 @@ umovestr(struct tcb *tcp, long addr, int len, char *laddr)
return -1;
}
started = 1;
- memcpy(laddr, &u.x[n], m = MIN(sizeof(long)-n, len));
+ m = MIN(sizeof(long) - n, len);
+ memcpy(laddr, &u.x[n], m);
while (n & (sizeof(long) - 1))
if (u.x[n++] == '\0')
return 1;
@@ -952,11 +958,11 @@ umovestr(struct tcb *tcp, long addr, int len, char *laddr)
return -1;
}
started = 1;
- memcpy(laddr, u.x, m = MIN(sizeof(long), len));
+ m = MIN(sizeof(long), len);
+ memcpy(laddr, u.x, m);
for (i = 0; i < sizeof(long); i++)
if (u.x[i] == '\0')
return 1;
-
addr += sizeof(long), laddr += m, len -= m;
}
#endif /* !USE_PROCFS */
@@ -1000,7 +1006,8 @@ uload(int cmd, int pid, long addr, int len, char *laddr)
perror("uload: POKE");
return -1;
}
- memcpy(&u.x[n], laddr, m = MIN(sizeof(long) - n, len));
+ m = MIN(sizeof(long) - n, len);
+ memcpy(&u.x[n], laddr, m);
if (ptrace(poke, pid, (char *)addr, u.val) < 0) {
perror("uload: POKE");
return -1;
@@ -1010,7 +1017,8 @@ uload(int cmd, int pid, long addr, int len, char *laddr)
while (len) {
if (len < sizeof(long))
u.val = ptrace(peek, pid, (char *) addr, 0);
- memcpy(u.x, laddr, m = MIN(sizeof(long), len));
+ m = MIN(sizeof(long), len);
+ memcpy(u.x, laddr, m);
if (ptrace(poke, pid, (char *) addr, u.val) < 0) {
perror("uload: POKE");
return -1;