From 8545368b421bcfead61a215301b224e900bbd2d6 Mon Sep 17 00:00:00 2001 From: Bjorn Winckler Date: Fri, 17 Aug 2012 18:21:16 +0200 Subject: [PATCH] Fix clang compiler and static analyzer warnings --- src/MacVim/MMAppController.m | 10 +++++----- src/MacVim/MMBackend.m | 8 ++++---- src/MacVim/MMCoreTextView.m | 3 +-- src/MacVim/MMTextStorage.m | 3 ++- src/MacVim/MMTextView.m | 2 +- src/MacVim/MMVimController.m | 32 ++++++++++++++++---------------- src/MacVim/MMVimView.m | 6 +++--- src/MacVim/gui_macvim.m | 11 ++++++----- 8 files changed, 38 insertions(+), 37 deletions(-) diff --git a/src/MacVim/MMAppController.m b/src/MacVim/MMAppController.m index 89a37f0aec..b77eb22e34 100644 --- a/src/MacVim/MMAppController.m +++ b/src/MacVim/MMAppController.m @@ -1205,7 +1205,7 @@ fsEventCallback(ConstFSEventStreamRef streamRef, kCFPreferencesCurrentApplication); CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication); - ASLogInfo(@"Use renderer=%d", renderer); + ASLogInfo(@"Use renderer=%ld", renderer); // This action is called when the user clicks the "use ATSUI renderer" // button in the advanced preferences pane. @@ -1807,8 +1807,8 @@ fsEventCallback(ConstFSEventStreamRef streamRef, [dict setObject:NSStringFromRange(range) forKey:@"selectionRange"]; } else { - ASLogErr(@"Xcode selection range size mismatch! got=%d expected=%d", - length, sizeof(MMXcodeSelectionRange)); + ASLogErr(@"Xcode selection range size mismatch! got=%ld " + "expected=%ld", length, sizeof(MMXcodeSelectionRange)); } } @@ -2393,11 +2393,11 @@ fsEventCallback(ConstFSEventStreamRef streamRef, if (r.length > 0) { // Select given range of characters. // TODO: This only works for encodings where 1 byte == 1 character - [a addObject:[NSString stringWithFormat:@"norm %dgov%dgo", + [a addObject:[NSString stringWithFormat:@"norm %ldgov%ldgo", r.location, NSMaxRange(r)-1]]; } else { // Position cursor on line at start of range. - [a addObject:[NSString stringWithFormat:@"norm %dGz.0", + [a addObject:[NSString stringWithFormat:@"norm %ldGz.0", r.location]]; } diff --git a/src/MacVim/MMBackend.m b/src/MacVim/MMBackend.m index d0527f7180..c818799496 100644 --- a/src/MacVim/MMBackend.m +++ b/src/MacVim/MMBackend.m @@ -1544,7 +1544,7 @@ extern GuiFont gui_mch_retain_font(GuiFont font); NSNumber *key = [NSNumber numberWithInt:port]; NSMutableArray *replies = [serverReplyDict objectForKey:key]; if (replies && [replies count]) { - ASLogDebug(@" %d replies, topmost is: %@", [replies count], + ASLogDebug(@" %ld replies, topmost is: %@", [replies count], [replies objectAtIndex:0]); return [replies objectAtIndex:0]; } @@ -2101,7 +2101,7 @@ static void netbeansReadCallback(CFSocketRef s, keyCode:(unsigned)code modifiers:(int)mods { - ASLogDebug(@"key='%@' code=%#x mods=%#x length=%d", key, code, mods, + ASLogDebug(@"key='%@' code=%#x mods=%#x length=%ld", key, code, mods, [key length]); if (!key) return; @@ -2829,10 +2829,10 @@ static void netbeansReadCallback(CFSocketRef s, NSString *cmd; if (range.length > 0) { // TODO: This only works for encodings where 1 byte == 1 character - cmd = [NSString stringWithFormat:@"%dgov%dgo", + cmd = [NSString stringWithFormat:@"%ldgov%ldgo", range.location, NSMaxRange(range)-1]; } else { - cmd = [NSString stringWithFormat:@"%dGz.0", + cmd = [NSString stringWithFormat:@"%ldGz.0", range.location]; } diff --git a/src/MacVim/MMCoreTextView.m b/src/MacVim/MMCoreTextView.m index 5fc385e7f5..0aa46a8bd6 100644 --- a/src/MacVim/MMCoreTextView.m +++ b/src/MacVim/MMCoreTextView.m @@ -1033,12 +1033,11 @@ recurseDraw(const unichar *chars, CGGlyph *glyphs, CGSize *advances, CFStringRef strRef = CFStringCreateWithCharactersNoCopy( NULL, chars, count, kCFAllocatorNull); CTFontRef newFontRef = CTFontCreateForString(fontRef, strRef, r); + CFRelease(strRef); if (!newFontRef) { - ASLogNotice(@"Cannot find font to draw chars: %@", strRef); CGFontRelease(cgFontRef); return; } - CFRelease(strRef); recurseDraw(chars, glyphs, advances, count, context, newFontRef, x0, y); diff --git a/src/MacVim/MMTextStorage.m b/src/MacVim/MMTextStorage.m index 9848314454..9d4b0e02bd 100644 --- a/src/MacVim/MMTextStorage.m +++ b/src/MacVim/MMTextStorage.m @@ -123,7 +123,8 @@ static NSString *MMWideCharacterAttributeName = @"MMWideChar"; withString:(NSString *)string { #if MM_TS_PARANOIA_LOG - ASLogWarn(@"Calling %s on MMTextStorage is unsupported", _cmd); + ASLogWarn(@"Calling %@ on MMTextStorage is unsupported", + NSStringFromSelector(_cmd)); #endif //[attribString replaceCharactersInRange:range withString:string]; } diff --git a/src/MacVim/MMTextView.m b/src/MacVim/MMTextView.m index 81dd03ffb8..3b9a7e4507 100644 --- a/src/MacVim/MMTextView.m +++ b/src/MacVim/MMTextView.m @@ -95,7 +95,7 @@ // system. Releasing the text storage will in turn release the layout // manager, the text container, and finally the text view (self). This // complicates deallocation somewhat, see -[MMVimView dealloc]. - if (![super initWithFrame:frame textContainer:tc]) { + if (!(self = [super initWithFrame:frame textContainer:tc])) { [textStorage release]; return nil; } diff --git a/src/MacVim/MMVimController.m b/src/MacVim/MMVimController.m index 9af99bcf24..4ab2ef5ee2 100644 --- a/src/MacVim/MMVimController.m +++ b/src/MacVim/MMVimController.m @@ -281,11 +281,11 @@ static BOOL isUnsafeMessage(int msgid); - (void)file:(NSString *)filename draggedToTabAtIndex:(NSUInteger)tabIndex { filename = normalizeFilename(filename); - ASLogInfo(@"filename=%@ index=%d", filename, tabIndex); + ASLogInfo(@"filename=%@ index=%ld", filename, tabIndex); NSString *fnEsc = [filename stringByEscapingSpecialFilenameCharacters]; NSString *input = [NSString stringWithFormat:@":silent " - "tabnext %d |" + "tabnext %ld |" "edit! %@", tabIndex + 1, fnEsc]; [self addVimInput:input]; } @@ -540,7 +540,7 @@ static BOOL isUnsafeMessage(int msgid); } if (delayQueue) { - ASLogDebug(@" Flushing delay queue (%d items)", + ASLogDebug(@" Flushing delay queue (%ld items)", [delayQueue count]/2); [self performSelector:@selector(processInputQueue:) withObject:delayQueue @@ -579,7 +579,7 @@ static BOOL isUnsafeMessage(int msgid); SetTextDimensionsReplyMsgID == msgid) { const void *bytes = [data bytes]; int rows = *((int*)bytes); bytes += sizeof(int); - int cols = *((int*)bytes); bytes += sizeof(int); + int cols = *((int*)bytes); // NOTE: When a resize message originated in the frontend, Vim // acknowledges it with a reply message. When this happens the window @@ -642,7 +642,7 @@ static BOOL isUnsafeMessage(int msgid); } else if (ShowToolbarMsgID == msgid) { const void *bytes = [data bytes]; int enable = *((int*)bytes); bytes += sizeof(int); - int flags = *((int*)bytes); bytes += sizeof(int); + int flags = *((int*)bytes); int mode = NSToolbarDisplayModeDefault; if (flags & ToolbarLabelFlag) { @@ -659,25 +659,25 @@ static BOOL isUnsafeMessage(int msgid); } else if (CreateScrollbarMsgID == msgid) { const void *bytes = [data bytes]; int32_t ident = *((int32_t*)bytes); bytes += sizeof(int32_t); - int type = *((int*)bytes); bytes += sizeof(int); + int type = *((int*)bytes); [windowController createScrollbarWithIdentifier:ident type:type]; } else if (DestroyScrollbarMsgID == msgid) { const void *bytes = [data bytes]; - int32_t ident = *((int32_t*)bytes); bytes += sizeof(int32_t); + int32_t ident = *((int32_t*)bytes); [windowController destroyScrollbarWithIdentifier:ident]; } else if (ShowScrollbarMsgID == msgid) { const void *bytes = [data bytes]; int32_t ident = *((int32_t*)bytes); bytes += sizeof(int32_t); - int visible = *((int*)bytes); bytes += sizeof(int); + int visible = *((int*)bytes); [windowController showScrollbarWithIdentifier:ident state:visible]; } else if (SetScrollbarPositionMsgID == msgid) { const void *bytes = [data bytes]; int32_t ident = *((int32_t*)bytes); bytes += sizeof(int32_t); int pos = *((int*)bytes); bytes += sizeof(int); - int len = *((int*)bytes); bytes += sizeof(int); + int len = *((int*)bytes); [windowController setScrollbarPosition:pos length:len identifier:ident]; @@ -685,7 +685,7 @@ static BOOL isUnsafeMessage(int msgid); const void *bytes = [data bytes]; int32_t ident = *((int32_t*)bytes); bytes += sizeof(int32_t); float val = *((float*)bytes); bytes += sizeof(float); - float prop = *((float*)bytes); bytes += sizeof(float); + float prop = *((float*)bytes); [windowController setScrollbarThumbValue:val proportion:prop identifier:ident]; @@ -724,7 +724,7 @@ static BOOL isUnsafeMessage(int msgid); } else if (SetDefaultColorsMsgID == msgid) { const void *bytes = [data bytes]; unsigned bg = *((unsigned*)bytes); bytes += sizeof(unsigned); - unsigned fg = *((unsigned*)bytes); bytes += sizeof(unsigned); + unsigned fg = *((unsigned*)bytes); NSColor *back = [NSColor colorWithArgbInt:bg]; NSColor *fore = [NSColor colorWithRgbInt:fg]; @@ -750,12 +750,12 @@ static BOOL isUnsafeMessage(int msgid); afterDelay:0]; } else if (SetMouseShapeMsgID == msgid) { const void *bytes = [data bytes]; - int shape = *((int*)bytes); bytes += sizeof(int); + int shape = *((int*)bytes); [windowController setMouseShape:shape]; } else if (AdjustLinespaceMsgID == msgid) { const void *bytes = [data bytes]; - int linespace = *((int*)bytes); bytes += sizeof(int); + int linespace = *((int*)bytes); [windowController adjustLinespace:linespace]; } else if (ActivateMsgID == msgid) { @@ -779,7 +779,7 @@ static BOOL isUnsafeMessage(int msgid); const void *bytes = [data bytes]; // state < 0 <-> some buffer modified // state > 0 <-> current buffer modified - int state = *((int*)bytes); bytes += sizeof(int); + int state = *((int*)bytes); // NOTE: The window controller tracks whether current buffer is // modified or not (and greys out the proxy icon as well as putting a @@ -842,7 +842,7 @@ static BOOL isUnsafeMessage(int msgid); const void *bytes = [data bytes]; int rows = *((int*)bytes); bytes += sizeof(int); int cols = *((int*)bytes); bytes += sizeof(int); - int state = *((int*)bytes); bytes += sizeof(int); + int state = *((int*)bytes); [windowController zoomWithRows:rows columns:cols @@ -850,7 +850,7 @@ static BOOL isUnsafeMessage(int msgid); } else if (SetWindowPositionMsgID == msgid) { const void *bytes = [data bytes]; int x = *((int*)bytes); bytes += sizeof(int); - int y = *((int*)bytes); bytes += sizeof(int); + int y = *((int*)bytes); // NOTE: Vim measures Y-coordinates from top of screen. NSRect frame = [[[windowController window] screen] frame]; diff --git a/src/MacVim/MMVimView.m b/src/MacVim/MMVimView.m index 7f618c6280..f2fb979f7c 100644 --- a/src/MacVim/MMVimView.m +++ b/src/MacVim/MMVimView.m @@ -83,7 +83,7 @@ enum { - (MMVimView *)initWithFrame:(NSRect)frame vimController:(MMVimController *)controller { - if (![super initWithFrame:frame]) + if (!(self = [super initWithFrame:frame])) return nil; vimController = controller; @@ -95,7 +95,7 @@ enum { NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; NSInteger renderer = [ud integerForKey:MMRendererKey]; - ASLogInfo(@"Use renderer=%d", renderer); + ASLogInfo(@"Use renderer=%ld", renderer); #if MM_ENABLE_ATSUI if (MMRendererATSUI == renderer) { @@ -107,7 +107,7 @@ enum { if (MMRendererCoreText == renderer) { // HACK! 'textView' has type MMTextView, but MMCoreTextView is not // derived from MMTextView. - textView = [[MMCoreTextView alloc] initWithFrame:frame]; + textView = (MMTextView *)[[MMCoreTextView alloc] initWithFrame:frame]; } #endif else { diff --git a/src/MacVim/gui_macvim.m b/src/MacVim/gui_macvim.m index 3a7400ec32..01f0ef8b5c 100644 --- a/src/MacVim/gui_macvim.m +++ b/src/MacVim/gui_macvim.m @@ -177,7 +177,7 @@ gui_macvim_after_fork_init() kCFPreferencesCurrentApplication, &keyValid); if (keyValid) { - ASLogInfo(@"Use renderer=%d", val); + ASLogInfo(@"Use renderer=%ld", val); use_gui_macvim_draw_string = (val != MMRendererCoreText); // For now only the Core Text renderer knows how to render graphical @@ -593,7 +593,7 @@ gui_mch_new_colors(void) gui.def_back_pixel = gui.back_pixel; gui.def_norm_pixel = gui.norm_pixel; - ASLogDebug(@"back=%x norm=%x", gui.def_back_pixel, gui.def_norm_pixel); + ASLogDebug(@"back=%ld norm=%ld", gui.def_back_pixel, gui.def_norm_pixel); [[MMBackend sharedInstance] setDefaultColorsBackground:gui.def_back_pixel @@ -748,7 +748,8 @@ gui_mch_add_menu_item(vimmenu_T *menu, int idx) ? menu->strings[MENU_INDEX_TIP] : menu->actext; NSArray *desc = descriptor_for_menu(menu); NSString *keyEquivalent = menu->mac_key - ? [NSString stringWithFormat:@"%C", specialKeyToNSKey(menu->mac_key)] + ? [NSString stringWithFormat:@"%C", + (unsigned short)specialKeyToNSKey(menu->mac_key)] : [NSString string]; int modifierMask = vimModMaskToEventModifierFlags(menu->mac_mods); char_u *icon = NULL; @@ -917,7 +918,7 @@ gui_mch_free_font(font) GuiFont font; { if (font != NOFONT) { - ASLogDebug(@"font=0x%x", font); + ASLogDebug(@"font=%p", font); [(id)font release]; } } @@ -1559,7 +1560,7 @@ gui_mch_get_rgb(guicolor_T pixel) void gui_mch_get_screen_dimensions(int *screen_w, int *screen_h) { - ASLogDebug(@"Columns=%d Rows=%d", Columns, Rows); + ASLogDebug(@"Columns=%ld Rows=%ld", Columns, Rows); *screen_w = Columns; *screen_h = Rows; }