From cb80d06c74ac6ba52fbfba8ecf5d5b2f06ba8c77 Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Fri, 27 Mar 2015 13:47:32 +0100 Subject: cdrom_id: unroll and simplify data check loop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit also removes this warning: src/udev/cdrom_id/cdrom_id.c: In function ‘cd_media_info.isra.13’: src/udev/cdrom_id/cdrom_id.c:612:12: warning: assuming signed overflow does not occur when assuming that (X + c) >= X is always true [-Wstrict-overflow] static int cd_media_info(struct udev *udev, int fd) ^ --- src/udev/cdrom_id/cdrom_id.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'src/udev') diff --git a/src/udev/cdrom_id/cdrom_id.c b/src/udev/cdrom_id/cdrom_id.c index 6052f6abd8..54a50756a8 100644 --- a/src/udev/cdrom_id/cdrom_id.c +++ b/src/udev/cdrom_id/cdrom_id.c @@ -650,8 +650,8 @@ static int cd_media_info(struct udev *udev, int fd) * write protected; we need to check the contents if it is blank */ if ((cd_media_dvd_rw_ro || cd_media_dvd_plus_rw || cd_media_dvd_plus_rw_dl || cd_media_dvd_ram) && (header[2] & 3) > 1) { unsigned char buffer[32 * 2048]; - unsigned char result, len; - int block, offset; + unsigned char len; + int offset; if (cd_media_dvd_ram) { /* a write protected dvd-ram may report "complete" status */ @@ -732,22 +732,23 @@ static int cd_media_info(struct udev *udev, int fd) /* if any non-zero data is found in sector 16 (iso and udf) or * eventually 0 (fat32 boot sector, ext2 superblock, etc), disc * is assumed non-blank */ - result = 0; - for (block = 32768; block >= 0 && !result; block -= 32768) { - offset = block; - while (offset < (block + 2048) && !result) { - result = buffer [offset]; - offset++; + for (offset = 32768; offset < (32768 + 2048); offset++) { + if (buffer [offset]) { + log_debug("data in block 16, assuming complete"); + goto determined; } } - if (!result) { - cd_media_state = media_status[0]; - log_debug("no data in blocks 0 or 16, assuming blank"); - } else { - log_debug("data in blocks 0 or 16, assuming complete"); + for (offset = 0; offset < 2048; offset++) { + if (buffer [offset]) { + log_debug("data in block 0, assuming complete"); + goto determined; + } } + + cd_media_state = media_status[0]; + log_debug("no data in blocks 0 or 16, assuming blank"); } determined: -- cgit v1.2.3-54-g00ecf