次のようなコードを見つけました(次のコードには多くの問題があります):
//setup consistent in each of the bad code examples
string someString;
char* nullValue = getenv("NONEXISTENT"); // some non-existent environment variable
// bad code example 1:
char x[1024];
sprintf(x," some text%s ", nullValue); //crashes on solaris, what about linux?
// bad code example 2:
someString += nullValue; // What happens here?
//bad code example 3:
someString.append(nullValue); // What happens here?
//bad code example 4:
string nextString=string(nullValue); //What happens here?
cout<<nextString;
私たちは、solaris、linux、gcc、sunstudio を使用しており、将来的には clang++ を使用する可能性が非常に高くなります。このコードの動作は、プラットフォームとコンパイラ全体で一貫していますか? 上記のコードのすべてのケースで予想される動作を説明する仕様を見つけることができませんでした。
現在、gcc を使用して (および Linux で) コードを実行する際に問題があります。上記のコードが原因でしょうか?
上記のコードがこれらすべての環境で同じように動作する場合、それは (動作がクラッシュであっても) 私にとって貴重な情報です。なぜなら、これが Linux の問題の原因ではないことがわかるからです。