diff options
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/SOURCES | 2 | ||||
-rw-r--r-- | firmware/common/dir_uncached.c | 11 | ||||
-rw-r--r-- | firmware/common/dircache.c | 28 | ||||
-rw-r--r-- | firmware/common/file.c | 3 | ||||
-rw-r--r-- | firmware/common/strlcpy.c | 52 | ||||
-rw-r--r-- | firmware/common/strncpy.c | 125 | ||||
-rw-r--r-- | firmware/drivers/fat.c | 4 | ||||
-rw-r--r-- | firmware/drivers/lcd-16bit.c | 2 | ||||
-rw-r--r-- | firmware/drivers/lcd-1bit-vert.c | 2 | ||||
-rw-r--r-- | firmware/drivers/lcd-2bit-vert.c | 2 | ||||
-rw-r--r-- | firmware/drivers/lcd-2bit-vi.c | 2 | ||||
-rw-r--r-- | firmware/drivers/lcd-charcell.c | 2 | ||||
-rw-r--r-- | firmware/general.c | 4 | ||||
-rw-r--r-- | firmware/include/string.h | 3 | ||||
-rw-r--r-- | firmware/logf.c | 2 |
15 files changed, 84 insertions, 160 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES index 50c57e3323..8e1cef31e0 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES | |||
@@ -52,7 +52,7 @@ common/strcmp.c | |||
52 | common/strnatcmp.c | 52 | common/strnatcmp.c |
53 | common/strcpy.c | 53 | common/strcpy.c |
54 | common/strncmp.c | 54 | common/strncmp.c |
55 | common/strncpy.c | 55 | common/strlcpy.c |
56 | common/strrchr.c | 56 | common/strrchr.c |
57 | common/strtok.c | 57 | common/strtok.c |
58 | common/strstr.c | 58 | common/strstr.c |
diff --git a/firmware/common/dir_uncached.c b/firmware/common/dir_uncached.c index c6af145930..25677a0903 100644 --- a/firmware/common/dir_uncached.c +++ b/firmware/common/dir_uncached.c | |||
@@ -58,8 +58,7 @@ int strip_volume(const char* name, char* namecopy) | |||
58 | name = "/"; /* else this must be the root dir */ | 58 | name = "/"; /* else this must be the root dir */ |
59 | } | 59 | } |
60 | 60 | ||
61 | strncpy(namecopy, name, MAX_PATH); | 61 | strlcpy(namecopy, name, MAX_PATH); |
62 | namecopy[MAX_PATH-1] = '\0'; | ||
63 | 62 | ||
64 | return volume; | 63 | return volume; |
65 | } | 64 | } |
@@ -120,8 +119,7 @@ DIR_UNCACHED* opendir_uncached(const char* name) | |||
120 | volume = strip_volume(name, namecopy); | 119 | volume = strip_volume(name, namecopy); |
121 | pdir->volumecounter = 0; | 120 | pdir->volumecounter = 0; |
122 | #else | 121 | #else |
123 | strncpy(namecopy,name,sizeof(namecopy)); /* just copy */ | 122 | strlcpy(namecopy, name, sizeof(namecopy)); /* just copy */ |
124 | namecopy[sizeof(namecopy)-1] = '\0'; | ||
125 | #endif | 123 | #endif |
126 | 124 | ||
127 | if ( fat_opendir(IF_MV2(volume,) &pdir->fatdir, 0, NULL) < 0 ) { | 125 | if ( fat_opendir(IF_MV2(volume,) &pdir->fatdir, 0, NULL) < 0 ) { |
@@ -204,7 +202,7 @@ struct dirent_uncached* readdir_uncached(DIR_UNCACHED* dir) | |||
204 | if ( !entry.name[0] ) | 202 | if ( !entry.name[0] ) |
205 | return NULL; | 203 | return NULL; |
206 | 204 | ||
207 | strncpy(theent->d_name, entry.name, sizeof( theent->d_name ) ); | 205 | strlcpy(theent->d_name, entry.name, sizeof(theent->d_name)); |
208 | theent->attribute = entry.attr; | 206 | theent->attribute = entry.attr; |
209 | theent->size = entry.filesize; | 207 | theent->size = entry.filesize; |
210 | theent->startcluster = entry.firstcluster; | 208 | theent->startcluster = entry.firstcluster; |
@@ -230,8 +228,7 @@ int mkdir_uncached(const char *name) | |||
230 | return -1; | 228 | return -1; |
231 | } | 229 | } |
232 | 230 | ||
233 | strncpy(namecopy,name,sizeof(namecopy)); | 231 | strlcpy(namecopy, name, sizeof(namecopy)); |
234 | namecopy[sizeof(namecopy)-1] = 0; | ||
235 | 232 | ||
236 | /* Split the base name and the path */ | 233 | /* Split the base name and the path */ |
237 | end = strrchr(namecopy, '/'); | 234 | end = strrchr(namecopy, '/'); |
diff --git a/firmware/common/dircache.c b/firmware/common/dircache.c index 01ed72adc1..e846d55452 100644 --- a/firmware/common/dircache.c +++ b/firmware/common/dircache.c | |||
@@ -232,11 +232,11 @@ static int dircache_scan(IF_MV2(int volume,) struct travel_data *td) | |||
232 | return -2; | 232 | return -2; |
233 | 233 | ||
234 | td->pathpos = strlen(dircache_cur_path); | 234 | td->pathpos = strlen(dircache_cur_path); |
235 | strncpy(&dircache_cur_path[td->pathpos], "/", | 235 | strlcpy(&dircache_cur_path[td->pathpos], "/", |
236 | sizeof(dircache_cur_path) - td->pathpos - 1); | 236 | sizeof(dircache_cur_path) - td->pathpos); |
237 | #ifdef SIMULATOR | 237 | #ifdef SIMULATOR |
238 | strncpy(&dircache_cur_path[td->pathpos+1], td->entry->d_name, | 238 | strlcpy(&dircache_cur_path[td->pathpos+1], td->entry->d_name, |
239 | sizeof(dircache_cur_path) - td->pathpos - 2); | 239 | sizeof(dircache_cur_path) - td->pathpos - 1); |
240 | 240 | ||
241 | td->newdir = opendir_uncached(dircache_cur_path); | 241 | td->newdir = opendir_uncached(dircache_cur_path); |
242 | if (td->newdir == NULL) | 242 | if (td->newdir == NULL) |
@@ -245,8 +245,8 @@ static int dircache_scan(IF_MV2(int volume,) struct travel_data *td) | |||
245 | return -3; | 245 | return -3; |
246 | } | 246 | } |
247 | #else | 247 | #else |
248 | strncpy(&dircache_cur_path[td->pathpos+1], td->entry.name, | 248 | strlcpy(&dircache_cur_path[td->pathpos+1], td->entry.name, |
249 | sizeof(dircache_cur_path) - td->pathpos - 2); | 249 | sizeof(dircache_cur_path) - td->pathpos - 1); |
250 | 250 | ||
251 | td->newdir = *td->dir; | 251 | td->newdir = *td->dir; |
252 | if (fat_opendir(IF_MV2(volume,) &td->newdir, | 252 | if (fat_opendir(IF_MV2(volume,) &td->newdir, |
@@ -399,7 +399,7 @@ static struct dircache_entry* dircache_get_entry(const char *path, | |||
399 | char* part; | 399 | char* part; |
400 | char* end; | 400 | char* end; |
401 | 401 | ||
402 | strncpy(namecopy, path, sizeof(namecopy) - 1); | 402 | strlcpy(namecopy, path, sizeof(namecopy)); |
403 | cache_entry = dircache_root; | 403 | cache_entry = dircache_root; |
404 | before = NULL; | 404 | before = NULL; |
405 | 405 | ||
@@ -926,7 +926,7 @@ static struct dircache_entry* dircache_new_entry(const char *path, int attribute | |||
926 | char *new; | 926 | char *new; |
927 | long last_cache_size = dircache_size; | 927 | long last_cache_size = dircache_size; |
928 | 928 | ||
929 | strncpy(basedir, path, sizeof(basedir)-1); | 929 | strlcpy(basedir, path, sizeof(basedir)); |
930 | new = strrchr(basedir, '/'); | 930 | new = strrchr(basedir, '/'); |
931 | if (new == NULL) | 931 | if (new == NULL) |
932 | { | 932 | { |
@@ -997,8 +997,8 @@ void dircache_bind(int fd, const char *path) | |||
997 | { | 997 | { |
998 | if (fdbind_idx >= MAX_PENDING_BINDINGS) | 998 | if (fdbind_idx >= MAX_PENDING_BINDINGS) |
999 | return ; | 999 | return ; |
1000 | strncpy(fdbind_cache[fdbind_idx].path, path, | 1000 | strlcpy(fdbind_cache[fdbind_idx].path, path, |
1001 | sizeof(fdbind_cache[fdbind_idx].path)-1); | 1001 | sizeof(fdbind_cache[fdbind_idx].path)); |
1002 | fdbind_cache[fdbind_idx].fd = fd; | 1002 | fdbind_cache[fdbind_idx].fd = fd; |
1003 | fdbind_idx++; | 1003 | fdbind_idx++; |
1004 | return ; | 1004 | return ; |
@@ -1141,7 +1141,7 @@ void dircache_rename(const char *oldpath, const char *newpath) | |||
1141 | /* Generate the absolute path for destination if necessary. */ | 1141 | /* Generate the absolute path for destination if necessary. */ |
1142 | if (newpath[0] != '/') | 1142 | if (newpath[0] != '/') |
1143 | { | 1143 | { |
1144 | strncpy(absolute_path, oldpath, sizeof(absolute_path)-1); | 1144 | strlcpy(absolute_path, oldpath, sizeof(absolute_path)); |
1145 | p = strrchr(absolute_path, '/'); | 1145 | p = strrchr(absolute_path, '/'); |
1146 | if (!p) | 1146 | if (!p) |
1147 | { | 1147 | { |
@@ -1151,7 +1151,7 @@ void dircache_rename(const char *oldpath, const char *newpath) | |||
1151 | } | 1151 | } |
1152 | 1152 | ||
1153 | *p = '\0'; | 1153 | *p = '\0'; |
1154 | strncpy(p, absolute_path, sizeof(absolute_path)-1-strlen(p)); | 1154 | strlcpy(p, absolute_path, sizeof(absolute_path)-strlen(p)); |
1155 | newpath = absolute_path; | 1155 | newpath = absolute_path; |
1156 | } | 1156 | } |
1157 | 1157 | ||
@@ -1246,7 +1246,7 @@ struct dircache_entry* readdir_cached(DIR_CACHED* dir) | |||
1246 | if (regentry == NULL) | 1246 | if (regentry == NULL) |
1247 | return NULL; | 1247 | return NULL; |
1248 | 1248 | ||
1249 | strncpy(dir->secondary_entry.d_name, regentry->d_name, MAX_PATH-1); | 1249 | strlcpy(dir->secondary_entry.d_name, regentry->d_name, MAX_PATH); |
1250 | dir->secondary_entry.size = regentry->size; | 1250 | dir->secondary_entry.size = regentry->size; |
1251 | dir->secondary_entry.startcluster = regentry->startcluster; | 1251 | dir->secondary_entry.startcluster = regentry->startcluster; |
1252 | dir->secondary_entry.attribute = regentry->attribute; | 1252 | dir->secondary_entry.attribute = regentry->attribute; |
@@ -1268,7 +1268,7 @@ struct dircache_entry* readdir_cached(DIR_CACHED* dir) | |||
1268 | 1268 | ||
1269 | dir->entry = ce->next; | 1269 | dir->entry = ce->next; |
1270 | 1270 | ||
1271 | strncpy(dir->secondary_entry.d_name, ce->d_name, MAX_PATH-1); | 1271 | strlcpy(dir->secondary_entry.d_name, ce->d_name, MAX_PATH); |
1272 | /* Can't do `dir->secondary_entry = *ce` | 1272 | /* Can't do `dir->secondary_entry = *ce` |
1273 | because that modifies the d_name pointer. */ | 1273 | because that modifies the d_name pointer. */ |
1274 | dir->secondary_entry.size = ce->size; | 1274 | dir->secondary_entry.size = ce->size; |
diff --git a/firmware/common/file.c b/firmware/common/file.c index 7c01f03817..3d7722f687 100644 --- a/firmware/common/file.c +++ b/firmware/common/file.c | |||
@@ -132,8 +132,7 @@ static int open_internal(const char* pathname, int flags, bool use_cache) | |||
132 | } | 132 | } |
133 | #endif | 133 | #endif |
134 | 134 | ||
135 | strncpy(pathnamecopy,pathname,sizeof(pathnamecopy)); | 135 | strlcpy(pathnamecopy, pathname, sizeof(pathnamecopy)); |
136 | pathnamecopy[sizeof(pathnamecopy)-1] = 0; | ||
137 | 136 | ||
138 | /* locate filename */ | 137 | /* locate filename */ |
139 | name=strrchr(pathnamecopy+1,'/'); | 138 | name=strrchr(pathnamecopy+1,'/'); |
diff --git a/firmware/common/strlcpy.c b/firmware/common/strlcpy.c new file mode 100644 index 0000000000..ac30ef01fe --- /dev/null +++ b/firmware/common/strlcpy.c | |||
@@ -0,0 +1,52 @@ | |||
1 | /* $OpenBSD: strlcpy.c,v 1.11 2006/05/05 15:27:38 millert Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | #include <sys/types.h> | ||
20 | #include <string.h> | ||
21 | |||
22 | /* | ||
23 | * Copy src to string dst of size siz. At most siz-1 characters | ||
24 | * will be copied. Always NUL terminates (unless siz == 0). | ||
25 | * Returns strlen(src); if retval >= siz, truncation occurred. | ||
26 | */ | ||
27 | size_t | ||
28 | strlcpy(char *dst, const char *src, size_t siz) | ||
29 | { | ||
30 | char *d = dst; | ||
31 | const char *s = src; | ||
32 | size_t n = siz; | ||
33 | |||
34 | /* Copy as many bytes as will fit */ | ||
35 | if (n != 0) { | ||
36 | while (--n != 0) { | ||
37 | if ((*d++ = *s++) == '\0') | ||
38 | break; | ||
39 | } | ||
40 | } | ||
41 | |||
42 | /* Not enough room in dst, add NUL and traverse rest of src */ | ||
43 | if (n == 0) { | ||
44 | if (siz != 0) | ||
45 | *d = '\0'; /* NUL-terminate dst */ | ||
46 | while (*s++) | ||
47 | ; | ||
48 | } | ||
49 | |||
50 | return(s - src - 1); /* count does not include NUL */ | ||
51 | } | ||
52 | |||
diff --git a/firmware/common/strncpy.c b/firmware/common/strncpy.c deleted file mode 100644 index 7c1973ba66..0000000000 --- a/firmware/common/strncpy.c +++ /dev/null | |||
@@ -1,125 +0,0 @@ | |||
1 | /* | ||
2 | FUNCTION | ||
3 | <<strncpy>>---counted copy string | ||
4 | |||
5 | INDEX | ||
6 | strncpy | ||
7 | |||
8 | ANSI_SYNOPSIS | ||
9 | #include <string.h> | ||
10 | char *strncpy(char *<[dst]>, const char *<[src]>, size_t <[length]>); | ||
11 | |||
12 | TRAD_SYNOPSIS | ||
13 | #include <string.h> | ||
14 | char *strncpy(<[dst]>, <[src]>, <[length]>) | ||
15 | char *<[dst]>; | ||
16 | char *<[src]>; | ||
17 | size_t <[length]>; | ||
18 | |||
19 | DESCRIPTION | ||
20 | <<strncpy>> copies not more than <[length]> characters from the | ||
21 | the string pointed to by <[src]> (including the terminating | ||
22 | null character) to the array pointed to by <[dst]>. If the | ||
23 | string pointed to by <[src]> is shorter than <[length]> | ||
24 | characters, null characters are appended to the destination | ||
25 | array until a total of <[length]> characters have been | ||
26 | written. | ||
27 | |||
28 | RETURNS | ||
29 | This function returns the initial value of <[dst]>. | ||
30 | |||
31 | PORTABILITY | ||
32 | <<strncpy>> is ANSI C. | ||
33 | |||
34 | <<strncpy>> requires no supporting OS subroutines. | ||
35 | |||
36 | QUICKREF | ||
37 | strncpy ansi pure | ||
38 | */ | ||
39 | |||
40 | #include <string.h> | ||
41 | #include <limits.h> | ||
42 | |||
43 | /*SUPPRESS 560*/ | ||
44 | /*SUPPRESS 530*/ | ||
45 | |||
46 | /* Nonzero if either X or Y is not aligned on a "long" boundary. */ | ||
47 | #define UNALIGNED(X, Y) \ | ||
48 | (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) | ||
49 | |||
50 | #if LONG_MAX == 2147483647L | ||
51 | #define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) | ||
52 | #else | ||
53 | #if LONG_MAX == 9223372036854775807L | ||
54 | /* Nonzero if X (a long int) contains a NULL byte. */ | ||
55 | #define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) | ||
56 | #else | ||
57 | #error long int is not a 32bit or 64bit type. | ||
58 | #endif | ||
59 | #endif | ||
60 | |||
61 | #ifndef DETECTNULL | ||
62 | #error long int is not a 32bit or 64bit byte | ||
63 | #endif | ||
64 | |||
65 | #define TOO_SMALL(LEN) ((LEN) < sizeof (long)) | ||
66 | |||
67 | char * | ||
68 | _DEFUN (strncpy, (dst0, src0), | ||
69 | char *dst0 _AND | ||
70 | _CONST char *src0 _AND | ||
71 | size_t count) | ||
72 | { | ||
73 | #if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) | ||
74 | char *dscan; | ||
75 | _CONST char *sscan; | ||
76 | |||
77 | dscan = dst0; | ||
78 | sscan = src0; | ||
79 | while (count > 0) | ||
80 | { | ||
81 | --count; | ||
82 | if ((*dscan++ = *sscan++) == '\0') | ||
83 | break; | ||
84 | } | ||
85 | while (count-- > 0) | ||
86 | *dscan++ = '\0'; | ||
87 | |||
88 | return dst0; | ||
89 | #else | ||
90 | char *dst = dst0; | ||
91 | _CONST char *src = src0; | ||
92 | long *aligned_dst; | ||
93 | _CONST long *aligned_src; | ||
94 | |||
95 | /* If SRC and DEST is aligned and count large enough, then copy words. */ | ||
96 | if (!UNALIGNED (src, dst) && !TOO_SMALL (count)) | ||
97 | { | ||
98 | aligned_dst = (long*)dst; | ||
99 | aligned_src = (long*)src; | ||
100 | |||
101 | /* SRC and DEST are both "long int" aligned, try to do "long int" | ||
102 | sized copies. */ | ||
103 | while (count >= sizeof (long int) && !DETECTNULL(*aligned_src)) | ||
104 | { | ||
105 | count -= sizeof (long int); | ||
106 | *aligned_dst++ = *aligned_src++; | ||
107 | } | ||
108 | |||
109 | dst = (char*)aligned_dst; | ||
110 | src = (char*)aligned_src; | ||
111 | } | ||
112 | |||
113 | while (count > 0) | ||
114 | { | ||
115 | --count; | ||
116 | if ((*dst++ = *src++) == '\0') | ||
117 | break; | ||
118 | } | ||
119 | |||
120 | while (count-- > 0) | ||
121 | *dst++ = '\0'; | ||
122 | |||
123 | return dst0; | ||
124 | #endif /* not PREFER_SIZE_OVER_SPEED */ | ||
125 | } | ||
diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c index 2ff4c61ac4..a710593a69 100644 --- a/firmware/drivers/fat.c +++ b/firmware/drivers/fat.c | |||
@@ -1183,7 +1183,7 @@ static int write_long_name(struct fat_file* file, | |||
1183 | /* shortname entry */ | 1183 | /* shortname entry */ |
1184 | unsigned short date=0, time=0, tenth=0; | 1184 | unsigned short date=0, time=0, tenth=0; |
1185 | LDEBUGF("Shortname entry: %s\n", shortname); | 1185 | LDEBUGF("Shortname entry: %s\n", shortname); |
1186 | strncpy(entry + FATDIR_NAME, shortname, 11); | 1186 | memcpy(entry + FATDIR_NAME, shortname, 11); |
1187 | entry[FATDIR_ATTR] = is_directory?FAT_ATTR_DIRECTORY:0; | 1187 | entry[FATDIR_ATTR] = is_directory?FAT_ATTR_DIRECTORY:0; |
1188 | entry[FATDIR_NTRES] = 0; | 1188 | entry[FATDIR_NTRES] = 0; |
1189 | 1189 | ||
@@ -1271,7 +1271,7 @@ static int add_dir_entry(struct fat_dir* dir, | |||
1271 | /* The "." and ".." directory entries must not be long names */ | 1271 | /* The "." and ".." directory entries must not be long names */ |
1272 | if(dotdir) { | 1272 | if(dotdir) { |
1273 | int i; | 1273 | int i; |
1274 | strncpy(shortname, name, 12); | 1274 | strlcpy(shortname, name, 12); |
1275 | for(i = strlen(shortname); i < 12; i++) | 1275 | for(i = strlen(shortname); i < 12; i++) |
1276 | shortname[i] = ' '; | 1276 | shortname[i] = ' '; |
1277 | 1277 | ||
diff --git a/firmware/drivers/lcd-16bit.c b/firmware/drivers/lcd-16bit.c index ef0865fc8c..882bfa0854 100644 --- a/firmware/drivers/lcd-16bit.c +++ b/firmware/drivers/lcd-16bit.c | |||
@@ -1152,7 +1152,7 @@ void lcd_puts_scroll_style_offset(int x, int y, const unsigned char *string, | |||
1152 | } | 1152 | } |
1153 | 1153 | ||
1154 | end = strchr(s->line, '\0'); | 1154 | end = strchr(s->line, '\0'); |
1155 | strncpy(end, string, current_vp->width/2); | 1155 | strlcpy(end, string, current_vp->width/2); |
1156 | 1156 | ||
1157 | s->vp = current_vp; | 1157 | s->vp = current_vp; |
1158 | s->y = y; | 1158 | s->y = y; |
diff --git a/firmware/drivers/lcd-1bit-vert.c b/firmware/drivers/lcd-1bit-vert.c index 5fb652431c..f11fd6fdf9 100644 --- a/firmware/drivers/lcd-1bit-vert.c +++ b/firmware/drivers/lcd-1bit-vert.c | |||
@@ -845,7 +845,7 @@ void LCDFN(puts_scroll_style_offset)(int x, int y, const unsigned char *string, | |||
845 | } | 845 | } |
846 | 846 | ||
847 | end = strchr(s->line, '\0'); | 847 | end = strchr(s->line, '\0'); |
848 | strncpy(end, string, current_vp->width/2); | 848 | strlcpy(end, string, current_vp->width/2); |
849 | 849 | ||
850 | s->vp = current_vp; | 850 | s->vp = current_vp; |
851 | s->y = y; | 851 | s->y = y; |
diff --git a/firmware/drivers/lcd-2bit-vert.c b/firmware/drivers/lcd-2bit-vert.c index 801927eb37..57d27d2ead 100644 --- a/firmware/drivers/lcd-2bit-vert.c +++ b/firmware/drivers/lcd-2bit-vert.c | |||
@@ -1154,7 +1154,7 @@ void lcd_puts_scroll_style_offset(int x, int y, const unsigned char *string, | |||
1154 | } | 1154 | } |
1155 | 1155 | ||
1156 | end = strchr(s->line, '\0'); | 1156 | end = strchr(s->line, '\0'); |
1157 | strncpy(end, (char *)string, current_vp->width/2); | 1157 | strlcpy(end, (char *)string, current_vp->width/2); |
1158 | 1158 | ||
1159 | s->vp = current_vp; | 1159 | s->vp = current_vp; |
1160 | s->y = y; | 1160 | s->y = y; |
diff --git a/firmware/drivers/lcd-2bit-vi.c b/firmware/drivers/lcd-2bit-vi.c index 1c0a717d13..0a73f0dd25 100644 --- a/firmware/drivers/lcd-2bit-vi.c +++ b/firmware/drivers/lcd-2bit-vi.c | |||
@@ -1167,7 +1167,7 @@ void LCDFN(puts_scroll_style_offset)(int x, int y, const unsigned char *string, | |||
1167 | } | 1167 | } |
1168 | 1168 | ||
1169 | end = strchr(s->line, '\0'); | 1169 | end = strchr(s->line, '\0'); |
1170 | strncpy(end, (char *)string, current_vp->width/2); | 1170 | strlcpy(end, (char *)string, current_vp->width/2); |
1171 | 1171 | ||
1172 | s->vp = current_vp; | 1172 | s->vp = current_vp; |
1173 | s->y = y; | 1173 | s->y = y; |
diff --git a/firmware/drivers/lcd-charcell.c b/firmware/drivers/lcd-charcell.c index ca5809899f..33337daf19 100644 --- a/firmware/drivers/lcd-charcell.c +++ b/firmware/drivers/lcd-charcell.c | |||
@@ -496,7 +496,7 @@ void lcd_puts_scroll_offset(int x, int y, const unsigned char *string, | |||
496 | } | 496 | } |
497 | 497 | ||
498 | end = strchr(s->line, '\0'); | 498 | end = strchr(s->line, '\0'); |
499 | strncpy(end, string, utf8seek(s->line, current_vp->width)); | 499 | strlcpy(end, string, utf8seek(s->line, current_vp->width)); |
500 | 500 | ||
501 | s->vp = current_vp; | 501 | s->vp = current_vp; |
502 | s->y = y; | 502 | s->y = y; |
diff --git a/firmware/general.c b/firmware/general.c index 14b2b55bf9..6f7238ead1 100644 --- a/firmware/general.c +++ b/firmware/general.c | |||
@@ -110,7 +110,7 @@ char *create_numbered_filename(char *buffer, const char *path, | |||
110 | char fmtstring[12]; | 110 | char fmtstring[12]; |
111 | 111 | ||
112 | if (buffer != path) | 112 | if (buffer != path) |
113 | strncpy(buffer, path, MAX_PATH); | 113 | strlcpy(buffer, path, MAX_PATH); |
114 | 114 | ||
115 | pathlen = strlen(buffer); | 115 | pathlen = strlen(buffer); |
116 | 116 | ||
@@ -185,7 +185,7 @@ char *create_datetime_filename(char *buffer, const char *path, | |||
185 | last_tm = *tm; | 185 | last_tm = *tm; |
186 | 186 | ||
187 | if (buffer != path) | 187 | if (buffer != path) |
188 | strncpy(buffer, path, MAX_PATH); | 188 | strlcpy(buffer, path, MAX_PATH); |
189 | 189 | ||
190 | pathlen = strlen(buffer); | 190 | pathlen = strlen(buffer); |
191 | snprintf(buffer + pathlen, MAX_PATH - pathlen, | 191 | snprintf(buffer + pathlen, MAX_PATH - pathlen, |
diff --git a/firmware/include/string.h b/firmware/include/string.h index 32b86cd2b0..6085c10eb6 100644 --- a/firmware/include/string.h +++ b/firmware/include/string.h | |||
@@ -35,13 +35,14 @@ char *_EXFUN(strerror,(int)); | |||
35 | size_t _EXFUN(strlen,(const char *)); | 35 | size_t _EXFUN(strlen,(const char *)); |
36 | char *_EXFUN(strncat,(char *, const char *, size_t)); | 36 | char *_EXFUN(strncat,(char *, const char *, size_t)); |
37 | int _EXFUN(strncmp,(const char *, const char *, size_t)); | 37 | int _EXFUN(strncmp,(const char *, const char *, size_t)); |
38 | char *_EXFUN(strncpy,(char *, const char *, size_t)); | ||
39 | char *_EXFUN(strpbrk,(const char *, const char *)); | 38 | char *_EXFUN(strpbrk,(const char *, const char *)); |
40 | char *_EXFUN(strrchr,(const char *, int)); | 39 | char *_EXFUN(strrchr,(const char *, int)); |
41 | size_t _EXFUN(strspn,(const char *, const char *)); | 40 | size_t _EXFUN(strspn,(const char *, const char *)); |
42 | char *_EXFUN(strstr,(const char *, const char *)); | 41 | char *_EXFUN(strstr,(const char *, const char *)); |
43 | char *_EXFUN(strcasestr,(const char *, const char *)); | 42 | char *_EXFUN(strcasestr,(const char *, const char *)); |
44 | 43 | ||
44 | size_t strlcpy(char *dst, const char *src, size_t siz); | ||
45 | |||
45 | #ifndef _REENT_ONLY | 46 | #ifndef _REENT_ONLY |
46 | char *_EXFUN(strtok,(char *, const char *)); | 47 | char *_EXFUN(strtok,(char *, const char *)); |
47 | #endif | 48 | #endif |
diff --git a/firmware/logf.c b/firmware/logf.c index a704ad2d67..6e3e532450 100644 --- a/firmware/logf.c +++ b/firmware/logf.c | |||
@@ -145,7 +145,7 @@ void _logf(const char *format, ...) | |||
145 | while(len > MAX_LOGF_ENTRY) | 145 | while(len > MAX_LOGF_ENTRY) |
146 | { | 146 | { |
147 | ptr = logfbuffer[logfindex]; | 147 | ptr = logfbuffer[logfindex]; |
148 | strncpy(ptr, buf + tlen, MAX_LOGF_ENTRY-1); | 148 | strlcpy(ptr, buf + tlen, MAX_LOGF_ENTRY); |
149 | ptr[MAX_LOGF_ENTRY] = LOGF_TERMINATE_CONTINUE_LINE; | 149 | ptr[MAX_LOGF_ENTRY] = LOGF_TERMINATE_CONTINUE_LINE; |
150 | logfindex++; | 150 | logfindex++; |
151 | check_logfindex(); | 151 | check_logfindex(); |