summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHarald Hoyer <harald@redhat.com>2015-03-27 13:47:32 +0100
committerAnthony G. Basile <blueness@gentoo.org>2015-04-12 11:40:28 -0400
commit59e0bf6c1fa5629d01e0793dd4457936d6e9019b (patch)
treef524fba25cfbf84ded74698629bebb0d872a2f1b /src
parent39de7639b455e981e9264ffca4291250b4bd4703 (diff)
cdrom_id: unroll and simplify data check loop
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) ^ Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'src')
-rw-r--r--src/cdrom_id/cdrom_id.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/src/cdrom_id/cdrom_id.c b/src/cdrom_id/cdrom_id.c
index 7bafd62809..b7782f8aa8 100644
--- a/src/cdrom_id/cdrom_id.c
+++ b/src/cdrom_id/cdrom_id.c
@@ -654,8 +654,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 */
@@ -736,22 +736,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: