Issue #13961 has been updated by jeremyevans0 (Jeremy Evans).

Status changed from Open to Closed

Fixed by commit:027cf467a4d093275b9c18fe694337765ff00213.

----------------------------------------
Bug #13961: String#unpack の warning メッセージが SHARABLE_MIDDLE_SUBSTRING=1 を考慮していない
https://bugs.ruby-lang.org/issues/13961#change-78820

* Author: tommy (Masahiro Tomita)
* Status: Closed
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.5.0dev (2017-10-01 trunk 60085) [x86_64-linux]
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
String#unpack で不正なディレクティブが指定された時のwarningメッセージが指定文字列ではなくNUL終端まで出力してしまいます。

```
% ruby -we '"hoge".unpack(("o"*100)[0,24])'
-e:1: warning: unknown unpack directive 'o' in 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo'
-e:1: warning: unknown unpack directive 'o' in 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo'
```

次のパッチで直ると思います。

```diff
diff --git a/pack.c b/pack.c
index 327c478af8..532e03cb14 100644
--- a/pack.c
+++ b/pack.c
@@ -1738,8 +1738,8 @@ pack_unpack_internal(VALUE str, VALUE fmt, int mode)
 	    break;
 
 	  default:
-	    rb_warning("unknown unpack directive '%c' in '%s'",
-		type, RSTRING_PTR(fmt));
+	    rb_warning("unknown unpack directive '%c' in '% "PRIsVALUE"'",
+		type, fmt);
 	    break;
 	}
     }
```



-- 
https://bugs.ruby-lang.org/