[openrtm-users 03049] 報告: rtc.conf に空白行があると起きるエラー, coil::Properties::load()

sasaki.akinori @ iri-tokyo.jp sasaki.akinori @ iri-tokyo.jp
2014年 6月 26日 (木) 22:09:54 JST


東京都立産業技術研究センターの佐々木と申します。


既知の内容かもしれませんが,下記のような coil の実行時エラーに
遭遇しましたので報告いたします。


テスト環境
--------------
- OpenRTM-aist-1.1.0-RELEASE (C++版), 32bit Windows版

- Visual C++ 2010 Express Edition, 32bit

  RTCBuilder + CMake で生成したソリューションファイルを利用し,
  [Debug] 構成でRTコンポーネントをビルド
 
- Windows 7 Professional (64bit)

  (ただし,潜在的には環境に依存しないエラー)

  
実行時エラーの内容
----------------------
RTコンポーネント(スタンドアローン)のロード時に
次のような assert 失敗 との メッセージウィンドウが表示される。

      C:\***\xxxcomp.exe
      File: c:\program files\microsoft visual studio 10.0\vc\include\xstring
      Line: 1441

      Expression: string subscript out of range

      For information on how your program can cause an assertion
      failure, see the Visual C++ documentation on asserts.

      (Press Retry to debug the application)

  

実行時エラーが発生する条件
--------------------------------
- RTコンポーネントが読み込んだ rtc.conf に空白行があること
  (行の位置には依存しない)


原因
-------------
coil::Properties::load() の実装

In trunk/OpenRTM-aist/src/lib/coil/common/Properties.cpp, Line 344--349:
(OpenRTM-aist-1.1.0-RELEASE においては,  */src/lib/coil/win32/coil/Properties.cpp)

   342      while(!inStream.eof())
   343        {
   344          std::string tmp;
   345          coil::getlinePortable(inStream, tmp);
   346          coil::eraseHeadBlank(tmp);
   347
   348          // Skip comments or empty lines
   349          if (tmp[0] == '#' || tmp[0] == '!' || tmp == "") continue;
   // 以下略

   --> tmp.empty() == true のとき 第0要素も存在しないので
       tmp[0] の評価時点で operator[] の実行中のどこかで assert に失敗する

       
改善案
---------

  349c349
  <       if (tmp[0] == '#' || tmp[0] == '!' || tmp == "") continue;
  ---
  >       if (tmp.empty() || tmp[0] == '#' || tmp[0] == '!') continue;
   
 --> ||演算子のオペランドは左から右に向かう順序で評価される
     https://www.jpcert.or.jp/sc-rules/c-exp10-c.html

     
もしくは,評価順序の知識なしで,実装の妥当性を判断できるように次のように変更  
  
  349c349,350
  <       if (tmp[0] == '#' || tmp[0] == '!' || tmp == "") continue;
  ---
  >       if (tmp.empty()) continue;
  >       if (tmp[0] == '#' || tmp[0] == '!') continue;


--
地方独立行政法人 東京都立産業技術研究センター
事業化支援本部 技術開発支援部 ロボット開発セクター
佐々木 智典




More information about the openrtm-users mailing list