Conversation
system7/Utils/S7Logging.m
Outdated
| va_list va_args; | ||
| va_start(va_args, format); | ||
| NSString *const nsFormat = [[NSString alloc] initWithCString:format encoding:NSUTF8StringEncoding]; | ||
| NSString *const nsFormat = [NSString stringWithFormat:@"%@", [NSString stringWithUTF8String:format]]; |
There was a problem hiding this comment.
we could write it even simpler with [NSString stringWithFormat:@"%s", format]; but I am not sure if we are prone to loose some of the characters, if we omit specifying the utf8 encoding.
There was a problem hiding this comment.
I think we haven't actually fixed the compliers complain, but piled one more level of indirection, so it cannot find an issue anymore.
Would suggest to use vfprintf here. And there.
There was a problem hiding this comment.
@pastey not sure I understand what you mean.
Do you mean, replacing the fprintf that we already have with vfprintf instead? It will still require the va_start/va_end, so it will be something like:
void logInfo(const char * __restrict format, ...) {
va_list va_args;
va_start(va_args, format);
withTTYLockDo(^{
vfprintf(stdout, format, va_args);
});
va_end(va_args);
}
but would that work with withTTYLockDo dispatch? My c++ knowledge is not extensive enough to know for sure :)
Alternatively, we could "prepare" the string with vsprintf first and then frpintf it as we do it now:
va_list va_args;
char message[256];
va_start (va_args, format);
vsprintf (message,format, va_args);
va_end (va_args);
char *messagePointer = message;
withTTYLockDo(^{
fprintf(stdout, "%s", messagePointer);
});
There was a problem hiding this comment.
also, the second logError function adds additional characters to the output when fprintf-ing it, so the "preparation" with vsprintf of the string seems to be the only way to go in that case.
There was a problem hiding this comment.
I think, vsprintf is a good option for this task 👍
system7/Utils/S7Logging.m
Outdated
| va_list va_args; | ||
| va_start(va_args, format); | ||
| NSString *const nsFormat = [[NSString alloc] initWithCString:format encoding:NSUTF8StringEncoding]; | ||
| NSString *const nsFormat = [NSString stringWithFormat:@"%@", [NSString stringWithUTF8String:format]]; |
There was a problem hiding this comment.
I think we haven't actually fixed the compliers complain, but piled one more level of indirection, so it cannot find an issue anymore.
Would suggest to use vfprintf here. And there.
|
@pastey some of the tests failed with the new changes, making this "quick fix" not so quick anymore :( If not, then how about I revert back to "shushing" Xcode 26 with the NSLog wrap, so we could merge it to make system7 usable on machines with Xcode 26, and then someone else could return to fixing it properly later? Also, fyi, I just checked the |
… macOS >= 10.14. If someone need s7 on earlier versions, we'll ask them to tweak the setting on their machine
When building with Xcode 26, there were two issues:
Passing 'printf' format string where 'NSString' format string is expectedWhere:
S7Logging.mWhy: Xcode oh so kindly warns us, that, you see, if you pass a
printfformat string to where an NSString format string is expected bad things could happen like incorrect output, security vulnerabilities (!) and even crashes (c) ChatGPTSo it's safer to wrap it up in @"%@" format;
Variable length array folded to constant array as an extensionWhere:
S7ConfigMergeDriver.mWhy: This error says that "" is not specific - or not constant - enough and when considering a code portability, other compilers or different compilation settings might treat
const unsigned int Ndifferently, leading to errors or unexpected behavior. Defining it with macro instead, "seals" the constant-ity of the array and thus - no more complaints :)Note
Bumps macOS deployment target to 14.6, rewrites logging to C-style printf formatting, adds a fopen NULL check in packed-refs parsing, and replaces a const buffer size with a macro in the merge driver.
MACOSX_DEPLOYMENT_TARGETto14.6insystem7.xcodeproj/project.pbxproj.system7/Utils/S7Logging.m):vsnprintfin newformatMessageand use it inlogInfo/logError(avoidNSStringformatting); free allocated buffers.system7/git/Git.m):.git/packed-refsinfindPackedReferenceMatchingPattern.system7/Merge Driver/S7ConfigMergeDriver.m):const int BUF_LENwith#define BUF_LENfor stdin buffer size.Written by Cursor Bugbot for commit bc6816e. This will update automatically on new commits. Configure here.