summaryrefslogtreecommitdiff
path: root/libvxi11client/libvxi11client.c
diff options
context:
space:
mode:
Diffstat (limited to 'libvxi11client/libvxi11client.c')
-rw-r--r--libvxi11client/libvxi11client.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/libvxi11client/libvxi11client.c b/libvxi11client/libvxi11client.c
index 743168f..0e01809 100644
--- a/libvxi11client/libvxi11client.c
+++ b/libvxi11client/libvxi11client.c
@@ -214,8 +214,10 @@ int vxi11_read(VXI11Context* context, char* buffer, unsigned int bufferlen, bool
#ifdef DEBUG
printf("Got \"%s\" from server\n", resp->data.data_val);
#endif
- if (buffer != NULL)
- strncpy(buffer, resp->data.data_val, (bufferlen < resp->data.data_len ? bufferlen : resp->data.data_len));
+ if (buffer != NULL && resp->data.data_val != NULL) {
+ int lengthtocopy = ((bufferlen - 1) < resp->data.data_len ? (bufferlen - 1) : resp->data.data_len);
+ strncpy(buffer, resp->data.data_val, lengthtocopy);
+ }
#ifdef DEBUG
else
printf("Supplied buffer is null!\n");