Changeset 3128
- Timestamp:
- Oct 28, 2008, 1:15:15 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/caca-php/php_caca.c
r3127 r3128 379 379 caca_event_t *event; 380 380 event = emalloc(sizeof(caca_event_t)); 381 if (!event) { 382 RETURN_FALSE; 383 } 381 384 ZEND_REGISTER_RESOURCE(return_value, event, le_caca_event); 382 385 } … … 1303 1306 ZEND_FETCH_RESOURCE(file, caca_file_t*, &_zval, -1, PHP_CACA_FILE_RES_NAME, le_caca_file); 1304 1307 1308 if (len < 1) { 1309 RETURN_FALSE; 1310 } 1305 1311 char *buffer = emalloc(len); 1312 if (!buffer) { 1313 RETURN_FALSE; 1314 } 1306 1315 caca_file_read(file, buffer, len); 1307 1316 … … 1324 1333 1325 1334 PHP_FUNCTION(caca_file_gets) { 1335 zval *_zval; 1336 long len = 0; 1337 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &_zval, &len) == FAILURE) { 1338 RETURN_FALSE; 1339 } 1340 caca_file_t *file; 1341 ZEND_FETCH_RESOURCE(file, caca_file_t*, &_zval, -1, PHP_CACA_FILE_RES_NAME, le_caca_file); 1342 1343 if (len < 1) { 1344 RETURN_FALSE; 1345 } 1346 char *buffer = emalloc(len); 1347 if (!buffer) { 1348 RETURN_FALSE; 1349 } 1350 char *result = caca_file_gets(file, buffer, len); 1351 if (!result) { 1352 RETURN_FALSE; 1353 } 1354 return_value->type = IS_STRING; 1355 return_value->value.str.len = len; 1356 return_value->value.str.val = result; 1326 1357 } 1327 1358 … … 1380 1411 ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas); 1381 1412 1382 void *buffer ;1413 void *buffer, *copy; 1383 1414 size_t len; 1384 1415 buffer = caca_export_memory(canvas, type, &len); 1385 if (!buffer) { 1386 RETURN_FALSE; 1387 } 1416 copy = emalloc(len); 1417 if (!buffer | !copy) { 1418 RETURN_FALSE; 1419 } 1420 memcpy(copy, buffer, len); 1421 free(buffer); 1422 1388 1423 return_value->type = IS_STRING; 1389 1424 return_value->value.str.len = len; 1390 return_value->value.str.val = emalloc(len); 1391 memcpy(return_value->value.str.val, buffer, len); 1392 free(buffer); 1425 return_value->value.str.val = copy; 1393 1426 } 1394 1427
Note: See TracChangeset
for help on using the changeset viewer.