diff options
author | Aidan MacDonald <amachronic@protonmail.com> | 2022-05-02 15:23:37 +0100 |
---|---|---|
committer | Aidan MacDonald <amachronic@protonmail.com> | 2022-05-02 15:38:48 +0100 |
commit | 6b8c94a6e3094ab75fcfe319fa2bc100f4e329ec (patch) | |
tree | 6c6ee0a2e7f77084f721ed33ff5b8856ec43fb61 /apps/plugins | |
parent | 366f00a3d3dc6517e7dcb1bbebb887c4f795320b (diff) | |
download | rockbox-6b8c94a6e3094ab75fcfe319fa2bc100f4e329ec.tar.gz rockbox-6b8c94a6e3094ab75fcfe319fa2bc100f4e329ec.zip |
Fix some non-portable alignment values
UBSan reports an avalanche of unaligned pointer bugs stemming from
hardcoded 4-byte alignments used in certain places. Use sizeof(long)
instead to align to the machine word size.
Change-Id: I28e505212462c5268afa24e95df3a103ac3e2213
Diffstat (limited to 'apps/plugins')
-rw-r--r-- | apps/plugins/pictureflow/pictureflow.c | 34 |
1 files changed, 10 insertions, 24 deletions
diff --git a/apps/plugins/pictureflow/pictureflow.c b/apps/plugins/pictureflow/pictureflow.c index 5136fc56e9..83d4bb5a59 100644 --- a/apps/plugins/pictureflow/pictureflow.c +++ b/apps/plugins/pictureflow/pictureflow.c | |||
@@ -1303,9 +1303,8 @@ static int build_artist_index(struct tagcache_search *tcs, | |||
1303 | if (res < SUCCESS) | 1303 | if (res < SUCCESS) |
1304 | return res; | 1304 | return res; |
1305 | 1305 | ||
1306 | ALIGN_BUFFER(*buf, *bufsz, 4); | ||
1307 | |||
1308 | /* finalize the artist index */ | 1306 | /* finalize the artist index */ |
1307 | ALIGN_BUFFER(*buf, *bufsz, alignof(struct artist_data)); | ||
1309 | tmp_artist = (struct artist_data*)*buf; | 1308 | tmp_artist = (struct artist_data*)*buf; |
1310 | for (i = pf_idx.artist_ct - 1; i >= 0; i--) | 1309 | for (i = pf_idx.artist_ct - 1; i >= 0; i--) |
1311 | tmp_artist[i] = pf_idx.artist_index[-i]; | 1310 | tmp_artist[i] = pf_idx.artist_index[-i]; |
@@ -1313,7 +1312,6 @@ static int build_artist_index(struct tagcache_search *tcs, | |||
1313 | pf_idx.artist_index = tmp_artist; | 1312 | pf_idx.artist_index = tmp_artist; |
1314 | /* move buf ptr to end of artist_index */ | 1313 | /* move buf ptr to end of artist_index */ |
1315 | *buf = pf_idx.artist_index + pf_idx.artist_ct; | 1314 | *buf = pf_idx.artist_index + pf_idx.artist_ct; |
1316 | ALIGN_BUFFER(*buf, *bufsz, 4); | ||
1317 | 1315 | ||
1318 | if (res == SUCCESS) | 1316 | if (res == SUCCESS) |
1319 | { | 1317 | { |
@@ -1384,14 +1382,14 @@ static int create_album_index(void) | |||
1384 | int i, j, last, final, retry, res; | 1382 | int i, j, last, final, retry, res; |
1385 | 1383 | ||
1386 | draw_splashscreen(buf, buf_size); | 1384 | draw_splashscreen(buf, buf_size); |
1387 | ALIGN_BUFFER(buf, buf_size, 4); | 1385 | ALIGN_BUFFER(buf, buf_size, sizeof(long)); |
1388 | 1386 | ||
1389 | /* Artists */ | 1387 | /* Artists */ |
1390 | res = build_artist_index(&tcs, &buf, &buf_size); | 1388 | res = build_artist_index(&tcs, &buf, &buf_size); |
1391 | if (res < SUCCESS) | 1389 | if (res < SUCCESS) |
1392 | return res; | 1390 | return res; |
1393 | 1391 | ||
1394 | /* Albums */ | 1392 | /* Albums */ |
1395 | pf_idx.album_ct = 0; | 1393 | pf_idx.album_ct = 0; |
1396 | pf_idx.album_len =0; | 1394 | pf_idx.album_len =0; |
1397 | pf_idx.album_untagged_idx = 0; | 1395 | pf_idx.album_untagged_idx = 0; |
@@ -1407,7 +1405,6 @@ static int create_album_index(void) | |||
1407 | rb->tagcache_search_finish(&tcs); | 1405 | rb->tagcache_search_finish(&tcs); |
1408 | if (res < SUCCESS) | 1406 | if (res < SUCCESS) |
1409 | return res; | 1407 | return res; |
1410 | ALIGN_BUFFER(buf, buf_size, 4); | ||
1411 | 1408 | ||
1412 | /* Build artist list for untagged albums */ | 1409 | /* Build artist list for untagged albums */ |
1413 | res = create_album_untagged(&tcs, &buf, &buf_size); | 1410 | res = create_album_untagged(&tcs, &buf, &buf_size); |
@@ -1415,9 +1412,8 @@ static int create_album_index(void) | |||
1415 | if (res < SUCCESS) | 1412 | if (res < SUCCESS) |
1416 | return res; | 1413 | return res; |
1417 | 1414 | ||
1418 | ALIGN_BUFFER(buf, buf_size, 4); | ||
1419 | |||
1420 | /* finalize the album index */ | 1415 | /* finalize the album index */ |
1416 | ALIGN_BUFFER(buf, buf_size, alignof(struct album_data)); | ||
1421 | tmp_album = (struct album_data*)buf; | 1417 | tmp_album = (struct album_data*)buf; |
1422 | for (i = pf_idx.album_ct - 1; i >= 0; i--) | 1418 | for (i = pf_idx.album_ct - 1; i >= 0; i--) |
1423 | tmp_album[i] = pf_idx.album_index[-i]; | 1419 | tmp_album[i] = pf_idx.album_index[-i]; |
@@ -1425,9 +1421,8 @@ static int create_album_index(void) | |||
1425 | pf_idx.album_index = tmp_album; | 1421 | pf_idx.album_index = tmp_album; |
1426 | /* move buf ptr to end of album_index */ | 1422 | /* move buf ptr to end of album_index */ |
1427 | buf = pf_idx.album_index + pf_idx.album_ct; | 1423 | buf = pf_idx.album_index + pf_idx.album_ct; |
1428 | ALIGN_BUFFER(buf, buf_size, 4); | ||
1429 | 1424 | ||
1430 | /* Assign indices */ | 1425 | /* Assign indices */ |
1431 | draw_splashscreen(buf, buf_size); | 1426 | draw_splashscreen(buf, buf_size); |
1432 | draw_progressbar(0, pf_idx.album_ct, "Assigning Albums"); | 1427 | draw_progressbar(0, pf_idx.album_ct, "Assigning Albums"); |
1433 | for (j = 0; j < pf_idx.album_ct; j++) | 1428 | for (j = 0; j < pf_idx.album_ct; j++) |
@@ -1541,7 +1536,6 @@ retry_artist_lookup: | |||
1541 | } | 1536 | } |
1542 | } | 1537 | } |
1543 | 1538 | ||
1544 | ALIGN_BUFFER(buf, buf_size, 4); | ||
1545 | pf_idx.buf = buf; | 1539 | pf_idx.buf = buf; |
1546 | pf_idx.buf_sz = buf_size; | 1540 | pf_idx.buf_sz = buf_size; |
1547 | pf_idx.artist_index = 0; | 1541 | pf_idx.artist_index = 0; |
@@ -1618,7 +1612,6 @@ static int load_album_index(void){ | |||
1618 | 1612 | ||
1619 | //rb->lseek(fr, sizeof(data) + 1, SEEK_SET); | 1613 | //rb->lseek(fr, sizeof(data) + 1, SEEK_SET); |
1620 | /* artist names */ | 1614 | /* artist names */ |
1621 | ALIGN_BUFFER(buf, buf_size, 4); | ||
1622 | if (read2buf(fr, buf, data.artist_len) == 0) | 1615 | if (read2buf(fr, buf, data.artist_len) == 0) |
1623 | goto failure; | 1616 | goto failure; |
1624 | 1617 | ||
@@ -1627,7 +1620,6 @@ static int load_album_index(void){ | |||
1627 | buf_size -= data.artist_len; | 1620 | buf_size -= data.artist_len; |
1628 | 1621 | ||
1629 | /* album names */ | 1622 | /* album names */ |
1630 | ALIGN_BUFFER(buf, buf_size, 4); | ||
1631 | if (read2buf(fr, buf, data.album_len) == 0) | 1623 | if (read2buf(fr, buf, data.album_len) == 0) |
1632 | goto failure; | 1624 | goto failure; |
1633 | 1625 | ||
@@ -1636,7 +1628,6 @@ static int load_album_index(void){ | |||
1636 | buf_size -= data.album_len; | 1628 | buf_size -= data.album_len; |
1637 | 1629 | ||
1638 | /* index of album names */ | 1630 | /* index of album names */ |
1639 | ALIGN_BUFFER(buf, buf_size, 4); | ||
1640 | if (read2buf(fr, buf, album_idx_sz) == 0) | 1631 | if (read2buf(fr, buf, album_idx_sz) == 0) |
1641 | goto failure; | 1632 | goto failure; |
1642 | 1633 | ||
@@ -4286,8 +4277,6 @@ static int pictureflow_main(const char* selected_file) | |||
4286 | init_scroll_lines(); | 4277 | init_scroll_lines(); |
4287 | init_reflect_table(); | 4278 | init_reflect_table(); |
4288 | 4279 | ||
4289 | ALIGN_BUFFER(pf_idx.buf, pf_idx.buf_sz, 4); | ||
4290 | |||
4291 | /*Scan will trigger when no file is found or the option was activated*/ | 4280 | /*Scan will trigger when no file is found or the option was activated*/ |
4292 | if ((pf_cfg.cache_version != CACHE_VERSION)||(load_album_index() < 0)){ | 4281 | if ((pf_cfg.cache_version != CACHE_VERSION)||(load_album_index() < 0)){ |
4293 | rb->splash(HZ/2,"Creating index, please wait"); | 4282 | rb->splash(HZ/2,"Creating index, please wait"); |
@@ -4312,23 +4301,20 @@ static int pictureflow_main(const char* selected_file) | |||
4312 | return PLUGIN_ERROR; | 4301 | return PLUGIN_ERROR; |
4313 | } | 4302 | } |
4314 | 4303 | ||
4315 | ALIGN_BUFFER(pf_idx.buf, pf_idx.buf_sz, 4); | 4304 | number_of_slides = pf_idx.album_ct; |
4316 | number_of_slides = pf_idx.album_ct; | ||
4317 | |||
4318 | size_t aa_bufsz = ALIGN_DOWN(pf_idx.buf_sz / 4, 0x4); | ||
4319 | 4305 | ||
4306 | size_t aa_bufsz = pf_idx.buf_sz / 4 + sizeof(long) - 1; | ||
4320 | if (aa_bufsz < DISPLAY_WIDTH * DISPLAY_HEIGHT * sizeof(pix_t)) | 4307 | if (aa_bufsz < DISPLAY_WIDTH * DISPLAY_HEIGHT * sizeof(pix_t)) |
4321 | { | 4308 | { |
4322 | error_wait("Not enough memory for album art cache"); | 4309 | error_wait("Not enough memory for album art cache"); |
4323 | return PLUGIN_ERROR; | 4310 | return PLUGIN_ERROR; |
4324 | } | 4311 | } |
4325 | 4312 | ||
4326 | pf_idx.buf_sz -= aa_bufsz; | 4313 | ALIGN_BUFFER(pf_idx.buf, pf_idx.buf_sz, sizeof(long)); |
4327 | ALIGN_BUFFER(pf_idx.buf, pf_idx.buf_sz, 4); | ||
4328 | aa_cache.buf = (char*) pf_idx.buf; | 4314 | aa_cache.buf = (char*) pf_idx.buf; |
4329 | aa_cache.buf_sz = aa_bufsz; | 4315 | aa_cache.buf_sz = aa_bufsz; |
4330 | pf_idx.buf += aa_bufsz; | 4316 | pf_idx.buf += aa_bufsz; |
4331 | ALIGN_BUFFER(pf_idx.buf, pf_idx.buf_sz, 4); | 4317 | pf_idx.buf_sz -= aa_bufsz; |
4332 | 4318 | ||
4333 | if (!create_empty_slide(pf_cfg.cache_version != CACHE_VERSION)) { | 4319 | if (!create_empty_slide(pf_cfg.cache_version != CACHE_VERSION)) { |
4334 | config_save(CACHE_REBUILD); | 4320 | config_save(CACHE_REBUILD); |