1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-11-29 01:03:57 +03:00

buffer: Cleanup buffer_verify

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
Andreas Schneider
2018-08-31 15:37:14 +02:00
parent 492e3d5c77
commit 29f36791c9

View File

@@ -25,6 +25,7 @@
#include <limits.h> #include <limits.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdbool.h>
#ifndef _WIN32 #ifndef _WIN32
#include <netinet/in.h> #include <netinet/in.h>
@@ -54,24 +55,38 @@
* *
* @param[in] buf The buffer to check. * @param[in] buf The buffer to check.
*/ */
static void buffer_verify(ssh_buffer buf){ static void buffer_verify(ssh_buffer buf)
int doabort=0; {
if(buf->data == NULL) bool do_abort = false;
return;
if(buf->used > buf->allocated){ if (buf->data == NULL) {
fprintf(stderr,"Buffer error : allocated %u, used %u\n",buf->allocated, buf->used); return;
doabort=1; }
}
if(buf->pos > buf->used){ if (buf->used > buf->allocated) {
fprintf(stderr,"Buffer error : position %u, used %u\n",buf->pos, buf->used); fprintf(stderr,
doabort=1; "BUFFER ERROR: allocated %u, used %u\n",
} buf->allocated,
if(buf->pos > buf->allocated){ buf->used);
fprintf(stderr,"Buffer error : position %u, allocated %u\n",buf->pos, buf->allocated); do_abort = true;
doabort=1; }
} if (buf->pos > buf->used) {
if(doabort) fprintf(stderr,
abort(); "BUFFER ERROR: position %u, used %u\n",
buf->pos,
buf->used);
do_abort = true;
}
if (buf->pos > buf->allocated) {
fprintf(stderr,
"BUFFER ERROR: position %u, allocated %u\n",
buf->pos,
buf->allocated);
do_abort = true;
}
if (do_abort) {
abort();
}
} }
#else #else