Browse Source

Fixes a variable argument crash if an incorrect number of arguments are passed in

Joshua Tessier 13 years ago
parent
commit
a79c1839c3
1 changed files with 12 additions and 4 deletions
  1. 12 4
      src/FMDatabase.m

+ 12 - 4
src/FMDatabase.m

@@ -630,12 +630,16 @@ - (FMResultSet *)executeQuery:(NSString *)sql withArgumentsInArray:(NSArray*)arr
             
         while (idx < queryCount) {
             
-            if (arrayArgs) {
+            if (arrayArgs && idx < [arrayArgs count]) {
                 obj = [arrayArgs objectAtIndex:(NSUInteger)idx];
             }
-            else {
+            else if (args) {
                 obj = va_arg(args, id);
             }
+			else {
+				//We ran out of arguments
+				break;
+			}
             
             if (_traceExecution) {
                 NSLog(@"obj: %@", obj);
@@ -815,12 +819,16 @@ - (BOOL)executeUpdate:(NSString*)sql error:(NSError**)outErr withArgumentsInArra
         
         while (idx < queryCount) {
             
-            if (arrayArgs) {
+            if (arrayArgs && idx < [arrayArgs count]) {
                 obj = [arrayArgs objectAtIndex:(NSUInteger)idx];
             }
-            else {
+            else if (args) {
                 obj = va_arg(args, id);
             }
+			else {
+				//We ran out of arguments
+				break;
+			}
             
             if (_traceExecution) {
                 NSLog(@"obj: %@", obj);