[ruby-list:37729] Win32 コマンドラインでのアクセス違反エラー

From: Shusaku <tsyk@...>
Date: 2003-05-27 07:14:58 UTC
List: ruby-list #37729
Shusakuです。

Windows版のrubyで間違えてUnix風なことをするとアクセス違反になります。

C:\>ruby -e "      => Access Violation

C:\>ruby -e '      => Access Violation

ちなみに ActivePerl v5.8.0 で試してみると、こうなりました。

C:\>perl -e "      (=> 何も起きない)

C:\>perl -e '
Can't find string terminator "'" anywhere before EOF at -e line 1.

これは win32.c にて、NtCmdLineElement->len = -1 になってしまうのが
原因であることが分かりました。修正個所(修正方法)にちょっと自信が
持てませんが、以下のようにすると…

C:\ruby-1.8.0>diff -u win32\win32.c.orig win32\win32.c
--- win32\win32.c.orig  2003-03-03 02:51:08.000000000 +0900
+++ win32\win32.c       2003-05-27 15:32:57.000000000 +0900
@@ -1209,7 +1209,7 @@
        // we can remove them.
        //

-       if (InputCmd && (base[0] == '\"' && base[len-1] == '\"')) {
+       if (InputCmd && (base[0] == '\"' && base[len-1] == '\"') && len > 2) {
            char *p;
            base++;
            len -= 2;
@@ -1221,7 +1221,7 @@
                }
            }
        }
-       else if (InputCmd && (base[0] == '\'' && base[len-1] == '\'')) {
+       else if (InputCmd && (base[0] == '\'' && base[len-1] == '\'') && len > 2) {
            base++;
            len -= 2;
        }

アクセス違反は回避されて、下のようなエラーに落ち着きます。

C:\ruby-1.8.0-build>ruby -e "
-e:1: unterminated string meets end of file

C:\ruby-1.8.0-build>ruby -e '
-e:1: unterminated string meets end of file

-- 
Shusaku <tsyk@yk.rim.or.jp>


In This Thread

Prev Next