Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit42f50cb

Browse files
committed
Fix overflow check in StringInfo; add missing casts
A few thinkos I introduced infa2fa99. Also, amend a similarlybroken comment.Report by Daniel Vérité.Authors: Daniel Vérité, Álvaro HerreraDiscussion:https://postgr.es/m/1706e85e-60d2-494e-8a64-9af1e1b2186e@manitou-mail.org
1 parente898437 commit42f50cb

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

‎src/backend/lib/stringinfo.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -313,19 +313,20 @@ enlargeStringInfo(StringInfo str, int needed)
313313
* for efficiency, double the buffer size each time it overflows.
314314
* Actually, we might need to more than double it if 'needed' is big...
315315
*/
316-
newlen=2*str->maxlen;
317-
while (needed>newlen)
316+
newlen=2*(Size)str->maxlen;
317+
while ((Size)needed>newlen)
318318
newlen=2*newlen;
319319

320320
/*
321-
* Clamp to the limit in case we went past it. Note we are assuming here
322-
* that limit <= INT_MAX/2, else the above loop could overflow. We will
323-
* still have newlen >= needed.
321+
* Clamp to the limit in case we went past it. (We used to depend on
322+
* limit <= INT32_MAX/2, to avoid overflow in the loop above; we no longer
323+
* depend on that, but if "needed" and str->maxlen ever become wider, we
324+
* will need similar caution here.) We will still have newlen >= needed.
324325
*/
325326
if (newlen>limit)
326327
newlen=limit;
327328

328-
str->data= (char*)repalloc_huge(str->data,(Size)newlen);
329+
str->data= (char*)repalloc_huge(str->data,newlen);
329330

330331
str->maxlen=newlen;
331332
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp