Skip to content

Commit 3cef8e6

Browse files
hunterhu3000nashif
authored andcommitted
tests: drivers: disk: Replace the MAX function with if and else
As the parameter of "MAX" is uint32, the nagetive number will be bigger than 0. The MAX function does not work as expected. So change it to if/else form. Fixes #51146 Signed-off-by: Hu Zhenyu <[email protected]>
1 parent 9f652ea commit 3cef8e6

File tree

1 file changed

+12
-2
lines changed
  • tests/drivers/disk/disk_access/src

1 file changed

+12
-2
lines changed

tests/drivers/disk/disk_access/src/main.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,12 @@ static void test_sector_read(uint8_t *buf, uint32_t num_sectors)
9494
rc = read_sector(buf, 0, num_sectors);
9595
zassert_equal(rc, 0, "Failed to read from sector zero");
9696
/* Read from a sector in the "middle" of the disk */
97-
sector = MAX(((disk_sector_count / 2) - num_sectors), 0);
97+
if (disk_sector_count / 2 > num_sectors) {
98+
sector = disk_sector_count / 2 - num_sectors;
99+
} else {
100+
sector = 0;
101+
}
102+
98103
rc = read_sector(buf, sector, num_sectors);
99104
zassert_equal(rc, 0, "Failed to read from mid disk sector");
100105
/* Read from the last sector */
@@ -147,7 +152,12 @@ static void test_sector_write(uint8_t *wbuf, uint8_t *rbuf, uint32_t num_sectors
147152
rc = write_sector_checked(wbuf, rbuf, 0, num_sectors);
148153
zassert_equal(rc, 0, "Failed to write to sector zero");
149154
/* Write to a sector in the "middle" of the disk */
150-
sector = MAX(((disk_sector_count / 2) - num_sectors), 0);
155+
if (disk_sector_count / 2 > num_sectors) {
156+
sector = disk_sector_count / 2 - num_sectors;
157+
} else {
158+
sector = 0;
159+
}
160+
151161
rc = write_sector_checked(wbuf, rbuf, sector, num_sectors);
152162
zassert_equal(rc, 0, "Failed to write to mid disk sector");
153163
/* Write to the last sector */

0 commit comments

Comments
 (0)