Sat Jul 20 13:13:33 2013 UTC ()
Initialise destination before performing stat structure conversion.
Avoid getting garbage for structure members not set explicitely.


(njoly)
diff -r1.26 -r1.27 src/sys/compat/netbsd32/netbsd32_conv.h

cvs diff -r1.26 -r1.27 src/sys/compat/netbsd32/netbsd32_conv.h (expand / switch to unified diff)

--- src/sys/compat/netbsd32/netbsd32_conv.h 2011/03/06 17:08:34 1.26
+++ src/sys/compat/netbsd32/netbsd32_conv.h 2013/07/20 13:13:33 1.27
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: netbsd32_conv.h,v 1.26 2011/03/06 17:08:34 bouyer Exp $ */ 1/* $NetBSD: netbsd32_conv.h,v 1.27 2013/07/20 13:13:33 njoly Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1998, 2001 Matthew R. Green 4 * Copyright (c) 1998, 2001 Matthew R. Green
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -373,76 +373,79 @@ netbsd32_to_timex(const struct netbsd32_ @@ -373,76 +373,79 @@ netbsd32_to_timex(const struct netbsd32_
373 txp->ppsfreq = (long)tx32p->ppsfreq; 373 txp->ppsfreq = (long)tx32p->ppsfreq;
374 txp->jitter = (long)tx32p->jitter; 374 txp->jitter = (long)tx32p->jitter;
375 txp->shift = tx32p->shift; 375 txp->shift = tx32p->shift;
376 txp->stabil = (long)tx32p->stabil; 376 txp->stabil = (long)tx32p->stabil;
377 txp->jitcnt = (long)tx32p->jitcnt; 377 txp->jitcnt = (long)tx32p->jitcnt;
378 txp->calcnt = (long)tx32p->calcnt; 378 txp->calcnt = (long)tx32p->calcnt;
379 txp->errcnt = (long)tx32p->errcnt; 379 txp->errcnt = (long)tx32p->errcnt;
380 txp->stbcnt = (long)tx32p->stbcnt; 380 txp->stbcnt = (long)tx32p->stbcnt;
381} 381}
382 382
383static __inline void 383static __inline void
384netbsd32_from___stat13(const struct stat *sbp, struct netbsd32_stat13 *sb32p) 384netbsd32_from___stat13(const struct stat *sbp, struct netbsd32_stat13 *sb32p)
385{ 385{
 386 memset(sb32p, 0, sizeof(*sb32p));
386 sb32p->st_dev = (uint32_t)sbp->st_dev; 387 sb32p->st_dev = (uint32_t)sbp->st_dev;
387 sb32p->st_ino = sbp->st_ino; 388 sb32p->st_ino = sbp->st_ino;
388 sb32p->st_mode = sbp->st_mode; 389 sb32p->st_mode = sbp->st_mode;
389 sb32p->st_nlink = sbp->st_nlink; 390 sb32p->st_nlink = sbp->st_nlink;
390 sb32p->st_uid = sbp->st_uid; 391 sb32p->st_uid = sbp->st_uid;
391 sb32p->st_gid = sbp->st_gid; 392 sb32p->st_gid = sbp->st_gid;
392 sb32p->st_rdev = (uint32_t)sbp->st_rdev; 393 sb32p->st_rdev = (uint32_t)sbp->st_rdev;
393 sb32p->st_size = sbp->st_size; 394 sb32p->st_size = sbp->st_size;
394 sb32p->st_atimespec.tv_sec = (int32_t)sbp->st_atimespec.tv_sec; 395 sb32p->st_atimespec.tv_sec = (int32_t)sbp->st_atimespec.tv_sec;
395 sb32p->st_atimespec.tv_nsec = (netbsd32_long)sbp->st_atimespec.tv_nsec; 396 sb32p->st_atimespec.tv_nsec = (netbsd32_long)sbp->st_atimespec.tv_nsec;
396 sb32p->st_mtimespec.tv_sec = (int32_t)sbp->st_mtimespec.tv_sec; 397 sb32p->st_mtimespec.tv_sec = (int32_t)sbp->st_mtimespec.tv_sec;
397 sb32p->st_mtimespec.tv_nsec = (netbsd32_long)sbp->st_mtimespec.tv_nsec; 398 sb32p->st_mtimespec.tv_nsec = (netbsd32_long)sbp->st_mtimespec.tv_nsec;
398 sb32p->st_ctimespec.tv_sec = (int32_t)sbp->st_ctimespec.tv_sec; 399 sb32p->st_ctimespec.tv_sec = (int32_t)sbp->st_ctimespec.tv_sec;
399 sb32p->st_ctimespec.tv_nsec = (netbsd32_long)sbp->st_ctimespec.tv_nsec; 400 sb32p->st_ctimespec.tv_nsec = (netbsd32_long)sbp->st_ctimespec.tv_nsec;
400 sb32p->st_blksize = sbp->st_blksize; 401 sb32p->st_blksize = sbp->st_blksize;
401 sb32p->st_blocks = sbp->st_blocks; 402 sb32p->st_blocks = sbp->st_blocks;
402 sb32p->st_flags = sbp->st_flags; 403 sb32p->st_flags = sbp->st_flags;
403 sb32p->st_gen = sbp->st_gen; 404 sb32p->st_gen = sbp->st_gen;
404 sb32p->st_birthtimespec.tv_sec = (int32_t)sbp->st_birthtimespec.tv_sec; 405 sb32p->st_birthtimespec.tv_sec = (int32_t)sbp->st_birthtimespec.tv_sec;
405 sb32p->st_birthtimespec.tv_nsec = (netbsd32_long)sbp->st_birthtimespec.tv_nsec; 406 sb32p->st_birthtimespec.tv_nsec = (netbsd32_long)sbp->st_birthtimespec.tv_nsec;
406} 407}
407 408
408static __inline void 409static __inline void
409netbsd32_from___stat50(const struct stat *sbp, struct netbsd32_stat50 *sb32p) 410netbsd32_from___stat50(const struct stat *sbp, struct netbsd32_stat50 *sb32p)
410{ 411{
 412 memset(sb32p, 0, sizeof(*sb32p));
411 sb32p->st_dev = (uint32_t)sbp->st_dev; 413 sb32p->st_dev = (uint32_t)sbp->st_dev;
412 sb32p->st_ino = sbp->st_ino; 414 sb32p->st_ino = sbp->st_ino;
413 sb32p->st_mode = sbp->st_mode; 415 sb32p->st_mode = sbp->st_mode;
414 sb32p->st_nlink = sbp->st_nlink; 416 sb32p->st_nlink = sbp->st_nlink;
415 sb32p->st_uid = sbp->st_uid; 417 sb32p->st_uid = sbp->st_uid;
416 sb32p->st_gid = sbp->st_gid; 418 sb32p->st_gid = sbp->st_gid;
417 sb32p->st_rdev = (uint32_t)sbp->st_rdev; 419 sb32p->st_rdev = (uint32_t)sbp->st_rdev;
418 sb32p->st_size = sbp->st_size; 420 sb32p->st_size = sbp->st_size;
419 sb32p->st_atimespec.tv_sec = (int32_t)sbp->st_atimespec.tv_sec; 421 sb32p->st_atimespec.tv_sec = (int32_t)sbp->st_atimespec.tv_sec;
420 sb32p->st_atimespec.tv_nsec = (netbsd32_long)sbp->st_atimespec.tv_nsec; 422 sb32p->st_atimespec.tv_nsec = (netbsd32_long)sbp->st_atimespec.tv_nsec;
421 sb32p->st_mtimespec.tv_sec = (int32_t)sbp->st_mtimespec.tv_sec; 423 sb32p->st_mtimespec.tv_sec = (int32_t)sbp->st_mtimespec.tv_sec;
422 sb32p->st_mtimespec.tv_nsec = (netbsd32_long)sbp->st_mtimespec.tv_nsec; 424 sb32p->st_mtimespec.tv_nsec = (netbsd32_long)sbp->st_mtimespec.tv_nsec;
423 sb32p->st_ctimespec.tv_sec = (int32_t)sbp->st_ctimespec.tv_sec; 425 sb32p->st_ctimespec.tv_sec = (int32_t)sbp->st_ctimespec.tv_sec;
424 sb32p->st_ctimespec.tv_nsec = (netbsd32_long)sbp->st_ctimespec.tv_nsec; 426 sb32p->st_ctimespec.tv_nsec = (netbsd32_long)sbp->st_ctimespec.tv_nsec;
425 sb32p->st_birthtimespec.tv_sec = (int32_t)sbp->st_birthtimespec.tv_sec; 427 sb32p->st_birthtimespec.tv_sec = (int32_t)sbp->st_birthtimespec.tv_sec;
426 sb32p->st_birthtimespec.tv_nsec = (netbsd32_long)sbp->st_birthtimespec.tv_nsec; 428 sb32p->st_birthtimespec.tv_nsec = (netbsd32_long)sbp->st_birthtimespec.tv_nsec;
427 sb32p->st_blksize = sbp->st_blksize; 429 sb32p->st_blksize = sbp->st_blksize;
428 sb32p->st_blocks = sbp->st_blocks; 430 sb32p->st_blocks = sbp->st_blocks;
429 sb32p->st_flags = sbp->st_flags; 431 sb32p->st_flags = sbp->st_flags;
430 sb32p->st_gen = sbp->st_gen; 432 sb32p->st_gen = sbp->st_gen;
431} 433}
432 434
433static __inline void 435static __inline void
434netbsd32_from_stat(const struct stat *sbp, struct netbsd32_stat *sb32p) 436netbsd32_from_stat(const struct stat *sbp, struct netbsd32_stat *sb32p)
435{ 437{
 438 memset(sb32p, 0, sizeof(*sb32p));
436 sb32p->st_dev = sbp->st_dev; 439 sb32p->st_dev = sbp->st_dev;
437 sb32p->st_ino = sbp->st_ino; 440 sb32p->st_ino = sbp->st_ino;
438 sb32p->st_mode = sbp->st_mode; 441 sb32p->st_mode = sbp->st_mode;
439 sb32p->st_nlink = sbp->st_nlink; 442 sb32p->st_nlink = sbp->st_nlink;
440 sb32p->st_uid = sbp->st_uid; 443 sb32p->st_uid = sbp->st_uid;
441 sb32p->st_gid = sbp->st_gid; 444 sb32p->st_gid = sbp->st_gid;
442 sb32p->st_rdev = sbp->st_rdev; 445 sb32p->st_rdev = sbp->st_rdev;
443 sb32p->st_size = sbp->st_size; 446 sb32p->st_size = sbp->st_size;
444 sb32p->st_atimespec.tv_sec = (netbsd32_time_t)sbp->st_atimespec.tv_sec; 447 sb32p->st_atimespec.tv_sec = (netbsd32_time_t)sbp->st_atimespec.tv_sec;
445 sb32p->st_atimespec.tv_nsec = (netbsd32_long)sbp->st_atimespec.tv_nsec; 448 sb32p->st_atimespec.tv_nsec = (netbsd32_long)sbp->st_atimespec.tv_nsec;
446 sb32p->st_mtimespec.tv_sec = (netbsd32_time_t)sbp->st_mtimespec.tv_sec; 449 sb32p->st_mtimespec.tv_sec = (netbsd32_time_t)sbp->st_mtimespec.tv_sec;
447 sb32p->st_mtimespec.tv_nsec = (netbsd32_long)sbp->st_mtimespec.tv_nsec; 450 sb32p->st_mtimespec.tv_nsec = (netbsd32_long)sbp->st_mtimespec.tv_nsec;
448 sb32p->st_ctimespec.tv_sec = (netbsd32_time_t)sbp->st_ctimespec.tv_sec; 451 sb32p->st_ctimespec.tv_sec = (netbsd32_time_t)sbp->st_ctimespec.tv_sec;