comparison src/ov-str-mat.cc @ 6151:12c50a17f20f

[project @ 2006-11-10 17:34:45 by jwe]
author jwe
date Fri, 10 Nov 2006 17:34:46 +0000
parents 85c7dc4afe6b
children b319df52ba87
comparison
equal deleted inserted replaced
6150:2ad8962722cc 6151:12c50a17f20f
368 for (int i = 0; i < elements; i++) 368 for (int i = 0; i < elements; i++)
369 { 369 {
370 int len; 370 int len;
371 if (extract_keyword (is, "length", len) && len >= 0) 371 if (extract_keyword (is, "length", len) && len >= 0)
372 { 372 {
373 OCTAVE_LOCAL_BUFFER (char, tmp, len+1); 373 // Use this instead of a C-style character
374 374 // buffer so that we can properly handle
375 if (len > 0 && ! 375 // embedded NUL characters.
376 is.read (tmp, len)) 376 charMatrix tmp (1, len);
377 char *ptmp = tmp.fortran_vec ();
378
379 if (len > 0 && ! is.read (ptmp, len))
377 { 380 {
378 error ("load: failed to load string constant"); 381 error ("load: failed to load string constant");
379 success = false; 382 success = false;
380 break; 383 break;
381 } 384 }
382 else 385 else
383 { 386 {
384 tmp [len] = '\0';
385 if (len > max_len) 387 if (len > max_len)
386 { 388 {
387 max_len = len; 389 max_len = len;
388 chm.resize (elements, max_len, 0); 390 chm.resize (elements, max_len, 0);
389 } 391 }
392
390 chm.insert (tmp, i, 0); 393 chm.insert (tmp, i, 0);
391 } 394 }
392 } 395 }
393 else 396 else
394 { 397 {
414 if (len >= 0) 417 if (len >= 0)
415 { 418 {
416 // This is cruft for backward compatiability, 419 // This is cruft for backward compatiability,
417 // but relatively harmless. 420 // but relatively harmless.
418 421
419 OCTAVE_LOCAL_BUFFER (char, tmp, len+1); 422 // Use this instead of a C-style character buffer so
420 423 // that we can properly handle embedded NUL characters.
421 if (len > 0 && ! is.read (tmp, len)) 424 charMatrix tmp (1, len);
425 char *ptmp = tmp.fortran_vec ();
426
427 if (len > 0 && ! is.read (ptmp, len))
422 { 428 {
423 error ("load: failed to load string constant"); 429 error ("load: failed to load string constant");
424 } 430 }
425 else 431 else
426 { 432 {
427 tmp [len] = '\0';
428
429 if (is) 433 if (is)
430 matrix = charMatrix (tmp); 434 matrix = tmp;
431 else 435 else
432 error ("load: failed to load string constant"); 436 error ("load: failed to load string constant");
433 } 437 }
434 } 438 }
435 } 439 }
522 int32_t len; 526 int32_t len;
523 if (! is.read (reinterpret_cast<char *> (&len), 4)) 527 if (! is.read (reinterpret_cast<char *> (&len), 4))
524 return false; 528 return false;
525 if (swap) 529 if (swap)
526 swap_bytes<4> (&len); 530 swap_bytes<4> (&len);
527 OCTAVE_LOCAL_BUFFER (char, btmp, len+1); 531 charMatrix btmp (1, len);
528 if (! is.read (reinterpret_cast<char *> (btmp), len)) 532 char *pbtmp = btmp.fortran_vec ();
533 if (! is.read (pbtmp, len))
529 return false; 534 return false;
530 if (len > max_len) 535 if (len > max_len)
531 { 536 {
532 max_len = len; 537 max_len = len;
533 chm.resize (elements, max_len, 0); 538 chm.resize (elements, max_len, 0);
534 } 539 }
535 btmp [len] = '\0';
536 chm.insert (btmp, i, 0); 540 chm.insert (btmp, i, 0);
537 } 541 }
538 matrix = chm; 542 matrix = chm;
539 } 543 }
540 return true; 544 return true;