comparison mac/dw.m @ 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
comparison
equal deleted inserted replaced
719:d5e49ef8f541 720:357b59e57a31
266 else 266 else
267 { 267 {
268 text = NULL; 268 text = NULL;
269 } 269 }
270 int result = treeselectfunc(handler->window, item, text, handler->data, user); 270 int result = treeselectfunc(handler->window, item, text, handler->data, user);
271 free(text); 271 if(text)
272 {
273 free(text);
274 }
272 return result; 275 return result;
273 } 276 }
274 277
275 return treeselectfunc(handler->window, item, text, handler->data, user); 278 return treeselectfunc(handler->window, item, text, handler->data, user);
276 } 279 }
3074 id object = handle; 3077 id object = handle;
3075 3078
3076 if([object isMemberOfClass:[DWComboBox class]]) 3079 if([object isMemberOfClass:[DWComboBox class]])
3077 { 3080 {
3078 DWComboBox *combo = handle; 3081 DWComboBox *combo = handle;
3079 NSString *nstr = [combo itemObjectValueAtIndex:index]; 3082 int count = (int)[combo numberOfItems];
3080 strncpy(buffer, [ nstr UTF8String ], length - 1); 3083
3084 if(index > count)
3085 {
3086 *buffer = '\0';
3087 }
3088 else
3089 {
3090 NSString *nstr = [combo itemObjectValueAtIndex:index];
3091 strncpy(buffer, [ nstr UTF8String ], length - 1);
3092 }
3081 } 3093 }
3082 else if([object isMemberOfClass:[DWContainer class]]) 3094 else if([object isMemberOfClass:[DWContainer class]])
3083 { 3095 {
3084 DWContainer *cont = handle; 3096 DWContainer *cont = handle;
3085 NSString *nstr = [cont getRow:index and:0]; 3097 int count = (int)[cont numberOfRowsInTableView:cont];
3086 3098
3087 strncpy(buffer, [ nstr UTF8String ], length - 1); 3099 if(index > count)
3100 {
3101 *buffer = '\0';
3102 }
3103 else
3104 {
3105 NSString *nstr = [cont getRow:index and:0];
3106
3107 strncpy(buffer, [ nstr UTF8String ], length - 1);
3108 }
3088 } 3109 }
3089 DW_MUTEX_UNLOCK; 3110 DW_MUTEX_UNLOCK;
3090 } 3111 }
3091 3112
3092 /* 3113 /*
3103 id object = handle; 3124 id object = handle;
3104 3125
3105 if([object isMemberOfClass:[DWComboBox class]]) 3126 if([object isMemberOfClass:[DWComboBox class]])
3106 { 3127 {
3107 DWComboBox *combo = handle; 3128 DWComboBox *combo = handle;
3129 int count = (int)[combo numberOfItems];
3108 3130
3109 [combo removeItemAtIndex:index]; 3131 if(index <= count)
3110 [combo insertItemWithObjectValue:[ NSString stringWithUTF8String:buffer ] atIndex:index]; 3132 {
3133 [combo removeItemAtIndex:index];
3134 [combo insertItemWithObjectValue:[ NSString stringWithUTF8String:buffer ] atIndex:index];
3135 }
3111 } 3136 }
3112 else if([object isMemberOfClass:[DWContainer class]]) 3137 else if([object isMemberOfClass:[DWContainer class]])
3113 { 3138 {
3114 DWContainer *cont = handle; 3139 DWContainer *cont = handle;
3115 NSString *nstr = [ NSString stringWithUTF8String:buffer ]; 3140 int count = (int)[cont numberOfRowsInTableView:cont];
3116 3141
3117 [cont editCell:nstr at:index and:0]; 3142 if(index <= count)
3118 [cont reloadData]; 3143 {
3144 NSString *nstr = [ NSString stringWithUTF8String:buffer ];
3145
3146 [cont editCell:nstr at:index and:0];
3147 [cont reloadData];
3148 }
3119 } 3149 }
3120 DW_MUTEX_UNLOCK; 3150 DW_MUTEX_UNLOCK;
3121 } 3151 }
3122 3152
3123 /* 3153 /*