You are correct. That code is invalid (using unspecified or undefined behavior). The spec is clear. It so happens that EOF is -1, so if toupper behaved any differently than it does now for -1, it would be in error.