mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
dthelp: Avoid undefined behaviour in strcpy
Technically strcpy's ranges cannot overlap at all, although in practice this is usually not an issue. Does quiet a valgrind warning, however.
This commit is contained in:
parent
7948362829
commit
4773d68153
1 changed files with 17 additions and 9 deletions
|
@ -4354,6 +4354,13 @@ FindSnbEntry(
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* A little helper function, acts like strcpy
|
||||||
|
* but safe for overlapping regions.
|
||||||
|
*/
|
||||||
|
static void *strmove(void *dest, const void *src) {
|
||||||
|
memmove(dest, src, strlen(src) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* Function: static int ProcessString(string, int idx);
|
* Function: static int ProcessString(string, int idx);
|
||||||
*
|
*
|
||||||
|
@ -4391,7 +4398,7 @@ ProcessString(
|
||||||
|
|
||||||
if (cpy_str == True)
|
if (cpy_str == True)
|
||||||
{
|
{
|
||||||
strcpy (string, &string[*idx+1]);
|
strmove (string, &string[*idx+1]);
|
||||||
*idx = -1;
|
*idx = -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -4451,7 +4458,7 @@ CompressLinkSeg(
|
||||||
* the string.
|
* the string.
|
||||||
*/
|
*/
|
||||||
if (_DtCvIsSegRegChar(p_seg))
|
if (_DtCvIsSegRegChar(p_seg))
|
||||||
strcpy(((char *)pChar), &(((char *)pChar)[1]));
|
strmove(((char *)pChar), &(((char *)pChar)[1]));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
@ -4496,7 +4503,7 @@ ProcessNonBreakChar(
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
my_struct->flags = my_struct->flags & ~(_DtCvNON_BREAK);
|
my_struct->flags = my_struct->flags & ~(_DtCvNON_BREAK);
|
||||||
strcpy (string, &string[*idx+1]);
|
strmove (string, &string[*idx+1]);
|
||||||
*idx = -1;
|
*idx = -1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -6983,6 +6990,7 @@ OnlyOneEach(
|
||||||
|
|
||||||
} /* End OnlyOneEach */
|
} /* End OnlyOneEach */
|
||||||
|
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* Function: int Cdata (FormatStruct my_struct,
|
* Function: int Cdata (FormatStruct my_struct,
|
||||||
* int cur_element, exceptions);
|
* int cur_element, exceptions);
|
||||||
|
@ -7063,7 +7071,7 @@ Cdata(
|
||||||
|
|
||||||
if (string[i] == '&')
|
if (string[i] == '&')
|
||||||
{
|
{
|
||||||
strcpy (&string[i], &string[i+1]);
|
strmove (&string[i], &string[i+1]);
|
||||||
if (string[i] == '\0')
|
if (string[i] == '\0')
|
||||||
{
|
{
|
||||||
string[i] = BufFileGet(my_struct->my_file);
|
string[i] = BufFileGet(my_struct->my_file);
|
||||||
|
@ -7154,7 +7162,7 @@ Cdata(
|
||||||
* and copy the rest of the string to after it.
|
* and copy the rest of the string to after it.
|
||||||
*/
|
*/
|
||||||
string[j-1] = (char) value;
|
string[j-1] = (char) value;
|
||||||
strcpy (&string[j], &string[i]);
|
strmove (&string[j], &string[i]);
|
||||||
i = j;
|
i = j;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7194,7 +7202,7 @@ Cdata(
|
||||||
if (my_struct->last_was_space == False)
|
if (my_struct->last_was_space == False)
|
||||||
my_struct->last_was_nl = True;
|
my_struct->last_was_nl = True;
|
||||||
|
|
||||||
strcpy (&string[i], &string[i+1]);
|
strmove (&string[i], &string[i+1]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -7208,7 +7216,7 @@ Cdata(
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy (string, &string[i+1]);
|
strmove (string, &string[i+1]);
|
||||||
i = 0;
|
i = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7217,7 +7225,7 @@ Cdata(
|
||||||
if (False == my_struct->save_blank &&
|
if (False == my_struct->save_blank &&
|
||||||
type != SdlTypeLiteral && type != SdlTypeUnlinedLiteral
|
type != SdlTypeLiteral && type != SdlTypeUnlinedLiteral
|
||||||
&& my_struct->last_was_space == True)
|
&& my_struct->last_was_space == True)
|
||||||
strcpy (&string[i], &string[i+1]);
|
strmove (&string[i], &string[i+1]);
|
||||||
else
|
else
|
||||||
i++;
|
i++;
|
||||||
my_struct->last_was_space = True;
|
my_struct->last_was_space = True;
|
||||||
|
@ -7242,7 +7250,7 @@ Cdata(
|
||||||
else /* the last was a multibyte character, tighten up */
|
else /* the last was a multibyte character, tighten up */
|
||||||
{
|
{
|
||||||
i--;
|
i--;
|
||||||
strcpy (&string[i], &string[i+1]);
|
strmove (&string[i], &string[i+1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue