Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/dist/smbfs/lib/smb Avoid lots of stupid alignement problems.



details:   https://anonhg.NetBSD.org/src/rev/96783adff0fb
branches:  trunk
changeset: 543244:96783adff0fb
user:      martin <martin%NetBSD.org@localhost>
date:      Thu Feb 20 14:07:12 2003 +0000

description:
Avoid lots of stupid alignement problems.
You can now actually use this on sparc64 systems. Unfortunately the
kernel part contains lots more of this ****** code.

diffstat:

 dist/smbfs/lib/smb/nb_name.c |  19 +++++++++++++------
 1 files changed, 13 insertions(+), 6 deletions(-)

diffs (49 lines):

diff -r 137fbcbfde57 -r 96783adff0fb dist/smbfs/lib/smb/nb_name.c
--- a/dist/smbfs/lib/smb/nb_name.c      Thu Feb 20 13:37:33 2003 +0000
+++ b/dist/smbfs/lib/smb/nb_name.c      Thu Feb 20 14:07:12 2003 +0000
@@ -145,9 +145,11 @@
 static void
 memsetw(char *dst, int n, u_short word)
 {
+       unsigned char c2 = word & 0x00ff;
+       unsigned char c1 = (word>>8) & 0x00ff;
        while (n--) {
-               *(u_short*)dst = word;
-               dst += 2;
+               *dst++ = c1;
+               *dst++ = c2;
        }
 }
 
@@ -157,22 +159,27 @@
        u_char *name, *plen;
        u_char *cp = dst;
        int i, lblen;
+       u_int16_t ch;
 
        *cp++ = NB_ENCNAMELEN;
        name = np->nn_name;
        if (name[0] == '*' && name[1] == 0) {
-               *(u_short*)cp = NBENCODE('*');
+               ch = NBENCODE('*');
+               memcpy(cp, &ch, 2);
                memsetw(cp + 2, NB_NAMELEN - 1, NBENCODE(' '));
                cp += NB_ENCNAMELEN;
        } else {
-               for (i = 0; *name && i < NB_NAMELEN; i++, cp += 2, name++)
-                       *(u_short*)cp = NBENCODE(toupper(*name));
+               for (i = 0; *name && i < NB_NAMELEN; i++, cp += 2, name++) {
+                       ch = NBENCODE(toupper(*name));
+                       memcpy(cp, &ch, 2);
+               }
                i = NB_NAMELEN - i - 1;
                if (i > 0) {
                        memsetw(cp, i, NBENCODE(' '));
                        cp += i * 2;
                }
-               *(u_short*)cp = NBENCODE(np->nn_type);
+               ch = NBENCODE(np->nn_type);
+               memcpy(cp, &ch, 2);
                cp += 2;
        }
        *cp = 0;



Home | Main Index | Thread Index | Old Index