NetBSD-Bugs archive

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

bin/50911: src/usr.sbin/makefs/chfs/chfs_mkfs.c:134: clumsy call to memset ?



>Number:         50911
>Category:       bin
>Synopsis:       src/usr.sbin/makefs/chfs/chfs_mkfs.c:134: clumsy call to memset ?
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Mar 07 12:25:00 +0000 2016
>Originator:     David Binderman
>Release:        cvs dated 20160305
>Organization:
>Environment:
>Description:

[src/usr.sbin/makefs/chfs/chfs_mkfs.c:127] -> [src/usr.sbin/makefs/chfs/chfs_mkfs.c:134]: (performance) Buffer 'buf' is being written before its old content has been used.

Source code is

    memset(buf, 0xFF, opts->pagesize);

    ebhdr.ec_hdr.magic = htole32(CHFS_MAGIC_BITMASK);
    ebhdr.ec_hdr.erase_cnt = htole32(1);
    ebhdr.ec_hdr.crc_ec = htole32(crc32(0,
        (uint8_t *)&ebhdr.ec_hdr + 8, 4));

    memcpy(buf, &ebhdr.ec_hdr, CHFS_EB_EC_HDR_SIZE);


Maybe better code
   


    ebhdr.ec_hdr.magic = htole32(CHFS_MAGIC_BITMASK);
    ebhdr.ec_hdr.erase_cnt = htole32(1);
    ebhdr.ec_hdr.crc_ec = htole32(crc32(0,
        (uint8_t *)&ebhdr.ec_hdr + 8, 4));

    memcpy(buf, &ebhdr.ec_hdr, CHFS_EB_EC_HDR_SIZE);
    memset(buf + CHFS_EB_EC_HDR_SIZE, 0xFF, opts->pagesize - CHFS_EB_EC_HDR_SIZE);

>How-To-Repeat:

>Fix:



Home | Main Index | Thread Index | Old Index