@@ -480,17 +480,20 @@ mpd_qresize(mpd_t *result, mpd_ssize_t nwords, uint32_t *status)
480480{
481481 assert (!mpd_isconst_data (result )); /* illegal operation for a const */
482482 assert (!mpd_isshared_data (result )); /* illegal operation for a shared */
483+ assert (MPD_MINALLOC <= result -> alloc );
483484
485+ nwords = (nwords <= MPD_MINALLOC ) ? MPD_MINALLOC : nwords ;
486+ if (nwords == result -> alloc ) {
487+ return 1 ;
488+ }
484489 if (mpd_isstatic_data (result )) {
485490 if (nwords > result -> alloc ) {
486491 return mpd_switch_to_dyn (result , nwords , status );
487492 }
488- }
489- else if (nwords != result -> alloc && nwords >= MPD_MINALLOC ) {
490- return mpd_realloc_dyn (result , nwords , status );
493+ return 1 ;
491494 }
492495
493- return 1 ;
496+ return mpd_realloc_dyn ( result , nwords , status ) ;
494497}
495498
496499/* Same as mpd_qresize, but the complete coefficient (including the old
@@ -500,20 +503,21 @@ mpd_qresize_zero(mpd_t *result, mpd_ssize_t nwords, uint32_t *status)
500503{
501504 assert (!mpd_isconst_data (result )); /* illegal operation for a const */
502505 assert (!mpd_isshared_data (result )); /* illegal operation for a shared */
506+ assert (MPD_MINALLOC <= result -> alloc );
503507
504- if (mpd_isstatic_data (result )) {
505- if (nwords > result -> alloc ) {
506- return mpd_switch_to_dyn_zero (result , nwords , status );
508+ nwords = (nwords <= MPD_MINALLOC ) ? MPD_MINALLOC : nwords ;
509+ if (nwords != result -> alloc ) {
510+ if (mpd_isstatic_data (result )) {
511+ if (nwords > result -> alloc ) {
512+ return mpd_switch_to_dyn_zero (result , nwords , status );
513+ }
507514 }
508- }
509- else if (nwords != result -> alloc && nwords >= MPD_MINALLOC ) {
510- if (!mpd_realloc_dyn (result , nwords , status )) {
515+ else if (!mpd_realloc_dyn (result , nwords , status )) {
511516 return 0 ;
512517 }
513518 }
514519
515520 mpd_uint_zero (result -> data , nwords );
516-
517521 return 1 ;
518522}
519523
0 commit comments