# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1300005156 0 # Node ID 357b59e57a31bbc3a15db3720656d09fcee23df8 # Parent d5e49ef8f541a06c41ce01d5a48ea54549875b08 Some fixes for out of range parameters passed to dw_listbox_g/set_text(). diff -r d5e49ef8f541 -r 357b59e57a31 mac/dw.m --- a/mac/dw.m Sun Mar 13 07:40:53 2011 +0000 +++ b/mac/dw.m Sun Mar 13 08:32:36 2011 +0000 @@ -268,7 +268,10 @@ text = NULL; } int result = treeselectfunc(handler->window, item, text, handler->data, user); - free(text); + if(text) + { + free(text); + } return result; } @@ -3076,15 +3079,33 @@ if([object isMemberOfClass:[DWComboBox class]]) { DWComboBox *combo = handle; - NSString *nstr = [combo itemObjectValueAtIndex:index]; - strncpy(buffer, [ nstr UTF8String ], length - 1); + int count = (int)[combo numberOfItems]; + + if(index > count) + { + *buffer = '\0'; + } + else + { + NSString *nstr = [combo itemObjectValueAtIndex:index]; + strncpy(buffer, [ nstr UTF8String ], length - 1); + } } else if([object isMemberOfClass:[DWContainer class]]) { DWContainer *cont = handle; - NSString *nstr = [cont getRow:index and:0]; + int count = (int)[cont numberOfRowsInTableView:cont]; - strncpy(buffer, [ nstr UTF8String ], length - 1); + if(index > count) + { + *buffer = '\0'; + } + else + { + NSString *nstr = [cont getRow:index and:0]; + + strncpy(buffer, [ nstr UTF8String ], length - 1); + } } DW_MUTEX_UNLOCK; } @@ -3105,17 +3126,26 @@ if([object isMemberOfClass:[DWComboBox class]]) { DWComboBox *combo = handle; + int count = (int)[combo numberOfItems]; - [combo removeItemAtIndex:index]; - [combo insertItemWithObjectValue:[ NSString stringWithUTF8String:buffer ] atIndex:index]; + if(index <= count) + { + [combo removeItemAtIndex:index]; + [combo insertItemWithObjectValue:[ NSString stringWithUTF8String:buffer ] atIndex:index]; + } } else if([object isMemberOfClass:[DWContainer class]]) { DWContainer *cont = handle; - NSString *nstr = [ NSString stringWithUTF8String:buffer ]; + int count = (int)[cont numberOfRowsInTableView:cont]; - [cont editCell:nstr at:index and:0]; - [cont reloadData]; + if(index <= count) + { + NSString *nstr = [ NSString stringWithUTF8String:buffer ]; + + [cont editCell:nstr at:index and:0]; + [cont reloadData]; + } } DW_MUTEX_UNLOCK; }