Stuart, if this were the Manic Miner game engine under consideration, then an unbounded search could indeed lead to a search well beyond the intended range of data. Because the data in stored in MM in such a way that each cell of the screen layout could potentially be populated with any attribute value between #00 and #FF.
However, in Jet Set Willy, because of the way that the room layouts are compressed/expanded, each screen cell can only hold one of the six attribute values defined in the table of room cell definitions. So by the time the program comes to execute the CPIR code (or any of the fixes put forward here to replace it), I don't believe that an unbounded search will take place in practice in the JSW engine.
That seems reasonable. However, it may worth noting that mine was a fix for both MM and JSW, and I wanted to avoid unnecessary differences between the MM version of the fix and the JSW version.
It did occur to me that JSW might be immune for the very reason that you state, but given that the JSW engine tends to be full of interesting “surprises”, I felt that it was safest to make the loop be bounded anyway.
I hope the hint of irony was clear enough in my initial announcement when I stated that it was “only” (!) 16-bytes long! As my version of the fix was intended for the Nightmare Edition I didn’t really expect many people to be typing it in as POKEs, so it did’t seem worth optimising it for size. I was fairly sure that no matter how hard I tried, others would do a better job of that, anyway: the main thing was to get the ball rolling. :-)
As a general fix for the problem, it’s worth considering that modifications to the JSW engine could easily break any assumption that screen cells can only hold attribute values defined in the block graphics table. Personally, I’d prefer use of an easily recognised game-wide block graphic as the default: perhaps the "?" character in the font, although I’m not so strongly oriented towards to the “quick and dirty” style of programming that wasn’t uncommon in 8-bit games programming, that’s also helpful in fitting everything in to such a small space!