Mercurial > dwindows
changeset 720:357b59e57a31
Some fixes for out of range parameters passed to dw_listbox_g/set_text().
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sun, 13 Mar 2011 08:32:36 +0000 |
parents | d5e49ef8f541 |
children | 56053f1af9ee |
files | mac/dw.m |
diffstat | 1 files changed, 40 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- 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; }