From: [EMAIL PROTECTED]
Operating system: mandrake linux
PHP version: 4.1.1
PHP Bug Type: Feature/Change Request
Bug description: shmop_write(): never writes the null char
I have a simple script that I'm trying to write/read to shared memory w/
the shmop_* functions. The problem is
that it ALWAYS gives me php warnings when reading the
value from shared memory. Doing some digging in the code
it seems that shmop_write always copies a string to
shared memory, but it NEVER null terminates it. This ALWAYS
causes shmop_read to report php warnings of
Warning: String is not zero-terminated (5�̏**�*@) (source:
zend_execute_API.c:274) in Unknown on line 0
I can't turn warnings off, just to avoid this issue. I need
warnings on for debugging of the rest of my site. MY question is,
shouldn't shmop_write() always memcopy the stringlen + the NULL character,
so when u do a read, this doesn't happen? I know, then u always have to
add 1 to the shmop_read(), but isn't that normal to assume u'd want the
strlen + 1 for the null char?
Here is my script
<?php
function xmp_var_dump( $var ) {
echo "<xmp>\n";
var_dump( $var );
echo "</xmp>\n";
}
$key = 0x0ff;
$semid = sem_get ( $key, 1, 0666 );
if ( !sem_acquire( $semid ) ) {
echo "Can't acquire semaphore<BR>";
exit;
}
$size = 100;
$shmid = shmop_open( $key, 'c', 0, 0 );
//shmop_delete($shmid);
//shmop_close($shmid);
//exit;
if ( $shmid == '' ) {
// Get register size:
// Create shared memory block
$shmid = shmop_open( $key, 'c', 0666, $size );
xmp_var_Dump( $shmid );
if ( $shmid == '' ) {
echo "mem.mem: Can't create shared memory";
} else {
// Set Header Info:
xmp_var_dump( "writing test");
shmop_write( $shmid, 5, 0 );
}
} else {
$var = shmop_read( $shmid, 0, 1);
xmp_var_dump( $var );
}
shmop_close($shmid);
if( !sem_release( $semid ) ) {
echo "find: Can't release semaphore";
exit();
}
?>
Warning: shmopen: can't get the block in
/home/waboring/devel/current/php/fo/shmem/example3.php on line 22
int(2) string(12) "writing test"
Warning: shwrite: write (5), len = 1 in
/home/waboring/devel/current/php/fo/shmem/example3.php on line 38
--
Edit bug report at http://bugs.php.net/?id=15527&edit=1
--
Fixed in CVS: http://bugs.php.net/fix.php?id=15527&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=15527&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=15527&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=15527&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=15527&r=support
Expected behavior: http://bugs.php.net/fix.php?id=15527&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=15527&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=15527&r=submittedtwice