summaryrefslogtreecommitdiffstats
path: root/src/udev/cdrom_id
diff options
context:
space:
mode:
authorHarald Hoyer <harald@redhat.com>2015-03-27 13:47:32 +0100
committerHarald Hoyer <harald@redhat.com>2015-03-27 14:57:38 +0100
commitcb80d06c74ac6ba52fbfba8ecf5d5b2f06ba8c77 (patch)
tree40093643347fca0ec38d2c1a25877471a1019fa6 /src/udev/cdrom_id
parentfix gcc warnings about uninitialized variables (diff)
downloadsystemd-cb80d06c74ac6ba52fbfba8ecf5d5b2f06ba8c77.tar.xz
systemd-cb80d06c74ac6ba52fbfba8ecf5d5b2f06ba8c77.zip
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) ^
Diffstat (limited to 'src/udev/cdrom_id')
-rw-r--r--src/udev/cdrom_id/cdrom_id.c27
1 files changed, 14 insertions, 13 deletions
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: