[前][次][番号順一覧][スレッド一覧]

ruby-changes:45049

From: rhe <ko1@a...>
Date: Tue, 20 Dec 2016 15:53:51 +0900 (JST)
Subject: [ruby-changes:45049] rhe:r57122 (trunk): string.c: add missing size_t cast

rhe	2016-12-20 15:53:45 +0900 (Tue, 20 Dec 2016)

  New Revision: 57122

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57122

  Log:
    string.c: add missing size_t cast
    
    Add size_t cast to avoid signed integer overflow. r56157 ("string.c:
    avoid signed integer overflow", 2016-09-13) missed this. Suppresses
    UBSan.

  Modified files:
    trunk/string.c
Index: string.c
===================================================================
--- string.c	(revision 57121)
+++ string.c	(revision 57122)
@@ -130,7 +130,7 @@ VALUE rb_cSymbol; https://github.com/ruby/ruby/blob/trunk/string.c#L130
 #define RESIZE_CAPA_TERM(str,capacity,termlen) do {\
     if (STR_EMBED_P(str)) {\
 	if (!STR_EMBEDDABLE_P(capacity, termlen)) {\
-	    char *const tmp = ALLOC_N(char, (capacity)+termlen);\
+	    char *const tmp = ALLOC_N(char, (size_t)(capacity) + (termlen));\
 	    const long tlen = RSTRING_LEN(str);\
 	    memcpy(tmp, RSTRING_PTR(str), tlen);\
 	    RSTRING(str)->as.heap.ptr = tmp;\

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]