Menu

#2 segmentation fault related to file size

open
nobody
None
8
2002-07-15
2002-07-15
No

this is a part of ciphers.c

=====
SNIP

if ((length % blocksize) !=0)
{
*buffer = realloc(*buffer, length + (blocksize - (length
%blocksize)));
#ifdef DEBUG
_printf ("LENGTH before fill: %d\n",length);
_printf ("FILLCOUNT: %d\n",blocksize - (length%
blocksize));
#endif

}
tmpbuf=*buffer;

for (i=1;i<=blocksize - (length%blocksize);i++)
tmpbuf[length+i]='\0';

SNAP

Occurs if: ...the filesize if a multipile of blocksize (during
encoding), for example blocksize = 16, filesize = 160.

-> no realloc
-> for (i = 1; i <= (16 - (160 % 16)); i++) {
16 - (160 % 16) == 16 but it SHOULD be 0.

I'd suggest you to move the for loop into the block
starting with if (length % blocksize) != 0).

Wait for more - I am still looking at it :)

Discussion

  • Henrik Mühe

    Henrik Mühe - 2002-07-15

    Logged In: YES
    user_id=453831

    And change

    *outbuflen = length+(blocksize - (length%blocksize));

    to

    *outbuflen = (length%blocksize == 0) ? length : length +
    (blocksize - (length%blocksize));

    while you are at it ;) but please check this line, I just wrote it
    from scratch....

     
  • Henrik Mühe

    Henrik Mühe - 2002-07-15
    • priority: 5 --> 8
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.