sezero / quakespasm

QuakeSpasm -- A modern, cross-platform Quake game engine based on FitzQuake.
https://sourceforge.net/projects/quakespasm/
GNU General Public License v2.0
244 stars 97 forks source link

Fix crash when handling clipboard data on macOS #68

Closed alexey-lysiuk closed 1 year ago

alexey-lysiuk commented 1 year ago

Attempt to paste text that contains non-ASCII characters leads to a crash Depending on code path, it's a copy from null pointer or an unhandled exception

sezero commented 1 year ago

Is that @try{} @catch() {} a requirement of the old code?

alexey-lysiuk commented 1 year ago

I cannot say for such old versions of macOS, but actual versions need it as exception is thrown when conversion fails.

sezero commented 1 year ago

I guess [clipboardString cString] implies an actual conversion to ASCII?

And, no exception thrown for the new [clipboardString cStringUsingEncoding: NSASCIIStringEncoding] ?

alexey-lysiuk commented 1 year ago

Yes, "new" path returns NULL if conversion fails.

sezero commented 1 year ago

OK then.

For old targets: Instead of try/catch, would it be safe to do the following?

        if (! [clipboardString canBeConvertedToEncoding:NSASCIIStringEncoding])
            return NULL;
        srcdata = [clipboardString cString];
alexey-lysiuk commented 1 year ago

Replaced exception handling with check for possibility of conversion to ASCII.

sezero commented 1 year ago

The patch is in, thank you! And I also applied it to uhexen2 project.