mirror of
https://github.com/vdr-projects/vdr.git
synced 2025-03-01 10:50:46 +00:00
Added parameter checks to strn0cpy() and Utf8Strn0Cpy()
This commit is contained in:
parent
657e5dda5d
commit
a7576f0b6c
@ -3374,6 +3374,7 @@ Stefan Hofmann <stefan.hofmann@t-online.de>
|
||||
for fixing some typos in the translation files
|
||||
for adding 1 to Utf8BufSize() for worst case
|
||||
for adding a header to the backtrace
|
||||
for adding parameter checks to strn0cpy()
|
||||
|
||||
Stefan Blochberger <Stefan.Blochberger@gmx.de>
|
||||
for suggesting to automatically display the progress display whenever replay of a
|
||||
|
1
HISTORY
1
HISTORY
@ -10053,3 +10053,4 @@ Video Disk Recorder Revision History
|
||||
- Fixed handling margins for timers that are not VPS controlled and not spawned (thanks
|
||||
to Markus Ehrnsperger).
|
||||
- Added a header to the backtrace (thanks to Stefan Hofmann).
|
||||
- Added parameter checks to strn0cpy() (thanks to Stefan Hofmann). Same for Utf8Strn0Cpy().
|
||||
|
33
tools.c
33
tools.c
@ -4,7 +4,7 @@
|
||||
* See the main source file 'vdr.c' for copyright information and
|
||||
* how to reach the author.
|
||||
*
|
||||
* $Id: tools.c 5.14 2024/09/01 20:43:40 kls Exp $
|
||||
* $Id: tools.c 5.15 2025/01/15 08:57:45 kls Exp $
|
||||
*/
|
||||
|
||||
#include "tools.h"
|
||||
@ -131,8 +131,11 @@ char *strcpyrealloc(char *dest, const char *src)
|
||||
char *strn0cpy(char *dest, const char *src, size_t n)
|
||||
{
|
||||
char *s = dest;
|
||||
for ( ; --n && (*dest = *src) != 0; dest++, src++) ;
|
||||
*dest = 0;
|
||||
if (dest && n) {
|
||||
if (src)
|
||||
for ( ; --n && (*dest = *src) != 0; dest++, src++) ;
|
||||
*dest = 0;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
@ -914,17 +917,21 @@ char *Utf8Strn0Cpy(char *Dest, const char *Src, int n)
|
||||
if (cCharSetConv::SystemCharacterTable())
|
||||
return strn0cpy(Dest, Src, n);
|
||||
char *d = Dest;
|
||||
while (*Src) {
|
||||
int sl = Utf8CharLen(Src);
|
||||
n -= sl;
|
||||
if (n > 0) {
|
||||
while (sl--)
|
||||
*d++ = *Src++;
|
||||
}
|
||||
else
|
||||
break;
|
||||
if (Dest && n > 0) {
|
||||
if (Src) {
|
||||
while (*Src) {
|
||||
int sl = Utf8CharLen(Src);
|
||||
n -= sl;
|
||||
if (n > 0) {
|
||||
while (sl--)
|
||||
*d++ = *Src++;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
*d = 0;
|
||||
*d = 0;
|
||||
}
|
||||
return Dest;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user