From 89d88b5f902f2136b0d07f2c0ca5fd78f75da9c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Tue, 17 Jan 2017 10:06:52 +0100 Subject: [PATCH] Version 16.118.2 --- swad_changelog.h | 3 ++- swad_string.c | 13 ++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/swad_changelog.h b/swad_changelog.h index 02ea084a7..63b9f2b72 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -191,13 +191,14 @@ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 16.118.1 (2017-01-16)" +#define Log_PLATFORM_VERSION "SWAD 16.118.2 (2017-01-17)" #define CSS_FILE "swad16.111.5.css" #define JS_FILE "swad16.114.js" // Number of lines (includes comments but not blank lines) has been got with the following command: // nl swad*.c swad*.h css/swad*.css py/swad*.py js/swad*.js soap/swad*?.h sql/swad*.sql | tail -1 /* + Version 16.118.2: Jan 17, 2017 Fix bug in string concatenation. (? lines) Version 16.118.1: Jan 17, 2017 Code refactoring related to string concatenation. (211850 lines) Version 16.118: Jan 17, 2017 Code refactoring related to string copy. (211676 lines) Version 16.117.1: Jan 16, 2017 Code refactoring related to string concatenation. (211229 lines) diff --git a/swad_string.c b/swad_string.c index 83ba6b457..181078499 100644 --- a/swad_string.c +++ b/swad_string.c @@ -2837,15 +2837,15 @@ void Str_Copy (char *Dst,const char *Src,size_t DstSize) { size_t LengthSrc = strlen (Src); - if (DstSize < LengthSrc) + /***** Check if buffer has enough space for source *****/ + if (LengthSrc > DstSize) { sprintf (Gbl.Message,"Trying to copy %lu chars into a %lu-chars buffer.", LengthSrc,DstSize); Lay_ShowErrorAndExit (Gbl.Message); } - // strncpy (Dst,Src,MaxLength); - // Dst[MaxLength] = '\0'; + /***** Copy source into destination *****/ strcpy (Dst,Src); } @@ -2859,14 +2859,17 @@ void Str_Concat (char *Dst,const char *Src,size_t DstSize) size_t LengthSrc; size_t FreeSpace; + /***** Check if buffer has already overflowed *****/ LengthDst = strlen (Dst); if (LengthDst > DstSize) { sprintf (Gbl.Message,"%lu-chars buffer has %lu chars!", - DstSize,LengthSrc); + DstSize,LengthDst); Lay_ShowErrorAndExit (Gbl.Message); } + /***** Check if buffer has enough space for source *****/ + // DstSize >= LengthDst ==> FreeSpace >= 0 FreeSpace = DstSize - LengthDst; LengthSrc = strlen (Src); if (FreeSpace < LengthSrc) @@ -2876,6 +2879,6 @@ void Str_Concat (char *Dst,const char *Src,size_t DstSize) Lay_ShowErrorAndExit (Gbl.Message); } - // strncat (Dst,Src,FreeSpace); + /***** Concatenate ******/ strcat (Dst,Src); }