*str++ = toupper(*str);

これ鼻から悪魔コード
インクリメント演算子で操作された変数が副作用完了点までに複数回参照するのは動作未定義

*str = toupper(*str);
str++;
と分離しないとまずい