Bug Summary

File:Frameworks/FriBidi Framework/NSString-FBAdditions.m
Location:line 47, column 11
Description:bad argument

Annotated Source Code

1//
2// NSString-FBAdditions.m
3// FriBidi
4//
5// Created by Ofri Wolfus on 22/08/06.
6// Copyright 2006 Ofri Wolfus. All rights reserved.
7//
8
9#import "NSString-FBAdditions.h"
10#import "fribidi.h"
11#import "ConvertUTF.h"
12
13
14@implementation NSString (FBAdditions)
15
16/*
17 * This method attempts to determine the base writing direction of our string.
18 * We do this by looping through our characters until we find the first one that knows its writing direction.
19 * This method will usually get the right direction, unless someone accidentally put a random letter at the
20 * beginning of the string, which has a different writing direction.
21 * But since this will be the user's fault, he'll have to deal with it :)
22 * Anyhow, AppKit also uses this method when displaying bidi text.
23 */
24- (NSWritingDirection)baseWritingDirection {
25 unsigned int len = [self length];
26 unsigned int i;
27 FriBidiChar *f, fch;
28 UTF16 *u, uch;
29 NSWritingDirection dir = NSWritingDirectionNatural;
30
31 /*
32 * Loop through all our characters, one by one, until we find one which knows its writing direction.
33 * Note: If our string begins with lots of universal characters (characters without a direction), this
34 * could get very inefficient.
35 */
[1] Loop condition is true. Entering loop body.
36 for (i = 0U; i < len; i++) {
37 FriBidiCharType type;
38
39 // Get a single character
40 uch = (UTF16)CFStringGetCharacterAtIndex((CFStringRef)self, i);
41 u = &uch;
42 f = &fch;
43
44 // Convert our UniChar (which is UTF16) to FriBidiChar (which is UTF32)
[2] Taking true branch.
45 if (ConvertUTF16toUTF32((const UTF16**)&u, (u + 1), &f, (f + 1), lenientConversion) == conversionOK) {
46 // Get the type of our character
[3] Pass-by-value argument in function is undefined.
47 type = fribidi_get_type(fch);
48
49 // LTR char?
50 if (type == FRIBIDI_TYPE_LTR( 0x00000010L + 0x00000100L )) {
51 dir = NSWritingDirectionLeftToRight;
52 break;
53 }
54
55 // RTL char?
56 if (type == FRIBIDI_TYPE_RTL( 0x00000010L + 0x00000100L + 0x00000001L )) {
57 dir = NSWritingDirectionRightToLeft;
58 break;
59 }
60 }
61 }
62
63 return dir;
64}
65
66@end