diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 34 | ||||
| -rw-r--r-- | src/doc.c | 2 | ||||
| -rw-r--r-- | src/fileio.c | 10 | ||||
| -rw-r--r-- | src/frame.c | 4 | ||||
| -rw-r--r-- | src/gtkutil.c | 2 | ||||
| -rw-r--r-- | src/keyboard.c | 10 | ||||
| -rw-r--r-- | src/lread.c | 28 | ||||
| -rw-r--r-- | src/nsmenu.m | 6 | ||||
| -rw-r--r-- | src/nsterm.m | 27 | ||||
| -rw-r--r-- | src/process.c | 9 | ||||
| -rw-r--r-- | src/regex.c | 2 | ||||
| -rw-r--r-- | src/s/gnu-linux.h | 3 | ||||
| -rw-r--r-- | src/s/sol2-6.h | 3 | ||||
| -rw-r--r-- | src/s/unixware.h | 3 | ||||
| -rw-r--r-- | src/sysdep.c | 18 | ||||
| -rw-r--r-- | src/widget.c | 14 | ||||
| -rw-r--r-- | src/xdisp.c | 10 |
17 files changed, 91 insertions, 94 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 84703fcdc2f..af0fc3a8e38 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,37 @@ | |||
| 1 | 2012-07-10 Paul Eggert <eggert@cs.ucla.edu> | ||
| 2 | |||
| 3 | Simplify by avoiding confusing use of strncpy etc. | ||
| 4 | * doc.c (Fsnarf_documentation): | ||
| 5 | * fileio.c (Ffile_name_directory, Fsubstitute_in_file_name): | ||
| 6 | * frame.c (Fmake_terminal_frame): | ||
| 7 | * gtkutil.c (get_utf8_string): | ||
| 8 | * lread.c (openp): | ||
| 9 | * nsmenu.m (ns_update_menubar): | ||
| 10 | * regex.c (regerror): | ||
| 11 | Prefer memcpy to strncpy and strncat when either will do. | ||
| 12 | * fileio.c (Fsubstitute_in_file_name): | ||
| 13 | * keyboard.c (MULTI_LETTER_MOD, parse_modifiers_uncached) | ||
| 14 | (menu_separator_name_p): | ||
| 15 | * nsmenu.m (ns_update_menubar): | ||
| 16 | Prefer memcmp to strncmp when either will do. | ||
| 17 | * nsterm.m: Include <ftoastr.h>. | ||
| 18 | (ns_get_color): | ||
| 19 | * s/gnu-linux.h, s/sol2-6.h, s/unixware.h (PTY_TTY_NAME_SPRINTF): | ||
| 20 | Prefer snprintf to strncpy. | ||
| 21 | * nsterm.m (ns_term_init): | ||
| 22 | * widget.c (set_frame_size) [0]: Prefer xstrdup to xmalloc + strncpy. | ||
| 23 | * nsterm.m (ns_term_init): | ||
| 24 | Avoid the need for strncpy, by using build_string or | ||
| 25 | make_unibyte_string directly. Use dtoastr, not snprintf. | ||
| 26 | * process.c (Fmake_network_process): Diagnose service names that | ||
| 27 | are too long, rather than silently truncating them or creating | ||
| 28 | non-null-terminated names. | ||
| 29 | (Fnetwork_interface_info): Likewise, for interface names. | ||
| 30 | * sysdep.c (system_process_attributes) [GNU_LINUX]: | ||
| 31 | Prefer sprintf to strncat. | ||
| 32 | * xdisp.c (debug_method_add) [GLYPH_DEBUG]: | ||
| 33 | Prefer vsnprintf to vsprintf + strncpy. | ||
| 34 | |||
| 1 | 2012-07-10 Glenn Morris <rgm@gnu.org> | 35 | 2012-07-10 Glenn Morris <rgm@gnu.org> |
| 2 | 36 | ||
| 3 | * dispnew.c (PENDING_OUTPUT_COUNT) [!__GNU_LIBRARY__]: | 37 | * dispnew.c (PENDING_OUTPUT_COUNT) [!__GNU_LIBRARY__]: |
| @@ -645,7 +645,7 @@ the same file name is found in the `doc-directory'. */) | |||
| 645 | { | 645 | { |
| 646 | ptrdiff_t len = end - p - 2; | 646 | ptrdiff_t len = end - p - 2; |
| 647 | char *fromfile = alloca (len + 1); | 647 | char *fromfile = alloca (len + 1); |
| 648 | strncpy (fromfile, &p[2], len); | 648 | memcpy (fromfile, &p[2], len); |
| 649 | fromfile[len] = 0; | 649 | fromfile[len] = 0; |
| 650 | if (fromfile[len-1] == 'c') | 650 | if (fromfile[len-1] == 'c') |
| 651 | fromfile[len-1] = 'o'; | 651 | fromfile[len-1] = 'o'; |
diff --git a/src/fileio.c b/src/fileio.c index 5d4ee1bde08..eccb1fbb559 100644 --- a/src/fileio.c +++ b/src/fileio.c | |||
| @@ -365,7 +365,7 @@ Given a Unix syntax file name, returns a string ending in slash. */) | |||
| 365 | 365 | ||
| 366 | if (p == beg + 4 && IS_DIRECTORY_SEP (*beg) && beg[1] == ':') | 366 | if (p == beg + 4 && IS_DIRECTORY_SEP (*beg) && beg[1] == ':') |
| 367 | { | 367 | { |
| 368 | strncpy (res, beg, 2); | 368 | memcpy (res, beg, 2); |
| 369 | beg += 2; | 369 | beg += 2; |
| 370 | r += 2; | 370 | r += 2; |
| 371 | } | 371 | } |
| @@ -1648,7 +1648,7 @@ those `/' is discarded. */) | |||
| 1648 | 1648 | ||
| 1649 | /* Copy out the variable name. */ | 1649 | /* Copy out the variable name. */ |
| 1650 | target = alloca (s - o + 1); | 1650 | target = alloca (s - o + 1); |
| 1651 | strncpy (target, o, s - o); | 1651 | memcpy (target, o, s - o); |
| 1652 | target[s - o] = 0; | 1652 | target[s - o] = 0; |
| 1653 | #ifdef DOS_NT | 1653 | #ifdef DOS_NT |
| 1654 | strupr (target); /* $home == $HOME etc. */ | 1654 | strupr (target); /* $home == $HOME etc. */ |
| @@ -1711,7 +1711,7 @@ those `/' is discarded. */) | |||
| 1711 | 1711 | ||
| 1712 | /* Copy out the variable name. */ | 1712 | /* Copy out the variable name. */ |
| 1713 | target = alloca (s - o + 1); | 1713 | target = alloca (s - o + 1); |
| 1714 | strncpy (target, o, s - o); | 1714 | memcpy (target, o, s - o); |
| 1715 | target[s - o] = 0; | 1715 | target[s - o] = 0; |
| 1716 | #ifdef DOS_NT | 1716 | #ifdef DOS_NT |
| 1717 | strupr (target); /* $home == $HOME etc. */ | 1717 | strupr (target); /* $home == $HOME etc. */ |
| @@ -1732,13 +1732,13 @@ those `/' is discarded. */) | |||
| 1732 | orig = make_unibyte_string (o, orig_length); | 1732 | orig = make_unibyte_string (o, orig_length); |
| 1733 | decoded = DECODE_FILE (orig); | 1733 | decoded = DECODE_FILE (orig); |
| 1734 | decoded_length = SBYTES (decoded); | 1734 | decoded_length = SBYTES (decoded); |
| 1735 | strncpy (x, SSDATA (decoded), decoded_length); | 1735 | memcpy (x, SDATA (decoded), decoded_length); |
| 1736 | x += decoded_length; | 1736 | x += decoded_length; |
| 1737 | 1737 | ||
| 1738 | /* If environment variable needed decoding, return value | 1738 | /* If environment variable needed decoding, return value |
| 1739 | needs to be multibyte. */ | 1739 | needs to be multibyte. */ |
| 1740 | if (decoded_length != orig_length | 1740 | if (decoded_length != orig_length |
| 1741 | || strncmp (SSDATA (decoded), o, orig_length)) | 1741 | || memcmp (SDATA (decoded), o, orig_length)) |
| 1742 | multibyte = 1; | 1742 | multibyte = 1; |
| 1743 | } | 1743 | } |
| 1744 | } | 1744 | } |
diff --git a/src/frame.c b/src/frame.c index 3a3f5526035..8d7981777bf 100644 --- a/src/frame.c +++ b/src/frame.c | |||
| @@ -646,7 +646,7 @@ affects all frames on the same terminal device. */) | |||
| 646 | if (!NILP (tty)) | 646 | if (!NILP (tty)) |
| 647 | { | 647 | { |
| 648 | name = alloca (SBYTES (tty) + 1); | 648 | name = alloca (SBYTES (tty) + 1); |
| 649 | strncpy (name, SSDATA (tty), SBYTES (tty)); | 649 | memcpy (name, SSDATA (tty), SBYTES (tty)); |
| 650 | name[SBYTES (tty)] = 0; | 650 | name[SBYTES (tty)] = 0; |
| 651 | } | 651 | } |
| 652 | 652 | ||
| @@ -657,7 +657,7 @@ affects all frames on the same terminal device. */) | |||
| 657 | if (!NILP (tty_type)) | 657 | if (!NILP (tty_type)) |
| 658 | { | 658 | { |
| 659 | type = alloca (SBYTES (tty_type) + 1); | 659 | type = alloca (SBYTES (tty_type) + 1); |
| 660 | strncpy (type, SSDATA (tty_type), SBYTES (tty_type)); | 660 | memcpy (type, SSDATA (tty_type), SBYTES (tty_type)); |
| 661 | type[SBYTES (tty_type)] = 0; | 661 | type[SBYTES (tty_type)] = 0; |
| 662 | } | 662 | } |
| 663 | 663 | ||
diff --git a/src/gtkutil.c b/src/gtkutil.c index f4551b4b9f7..290ecef9216 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c | |||
| @@ -529,7 +529,7 @@ get_utf8_string (const char *str) | |||
| 529 | &bytes_written, &err)) | 529 | &bytes_written, &err)) |
| 530 | && err->code == G_CONVERT_ERROR_ILLEGAL_SEQUENCE) | 530 | && err->code == G_CONVERT_ERROR_ILLEGAL_SEQUENCE) |
| 531 | { | 531 | { |
| 532 | strncpy (up, (char *)p, bytes_written); | 532 | memcpy (up, p, bytes_written); |
| 533 | sprintf (up + bytes_written, "\\%03o", p[bytes_written]); | 533 | sprintf (up + bytes_written, "\\%03o", p[bytes_written]); |
| 534 | up += bytes_written+4; | 534 | up += bytes_written+4; |
| 535 | p += bytes_written+1; | 535 | p += bytes_written+1; |
diff --git a/src/keyboard.c b/src/keyboard.c index 71c8d869ece..b34d3c470a5 100644 --- a/src/keyboard.c +++ b/src/keyboard.c | |||
| @@ -6134,7 +6134,7 @@ parse_modifiers_uncached (Lisp_Object symbol, ptrdiff_t *modifier_end) | |||
| 6134 | 6134 | ||
| 6135 | #define MULTI_LETTER_MOD(BIT, NAME, LEN) \ | 6135 | #define MULTI_LETTER_MOD(BIT, NAME, LEN) \ |
| 6136 | if (i + LEN + 1 <= SBYTES (name) \ | 6136 | if (i + LEN + 1 <= SBYTES (name) \ |
| 6137 | && ! strncmp (SSDATA (name) + i, NAME, LEN)) \ | 6137 | && ! memcmp (SDATA (name) + i, NAME, LEN)) \ |
| 6138 | { \ | 6138 | { \ |
| 6139 | this_mod_end = i + LEN; \ | 6139 | this_mod_end = i + LEN; \ |
| 6140 | this_mod = BIT; \ | 6140 | this_mod = BIT; \ |
| @@ -6172,13 +6172,13 @@ parse_modifiers_uncached (Lisp_Object symbol, ptrdiff_t *modifier_end) | |||
| 6172 | if (! (modifiers & (down_modifier | drag_modifier | 6172 | if (! (modifiers & (down_modifier | drag_modifier |
| 6173 | | double_modifier | triple_modifier)) | 6173 | | double_modifier | triple_modifier)) |
| 6174 | && i + 7 == SBYTES (name) | 6174 | && i + 7 == SBYTES (name) |
| 6175 | && strncmp (SSDATA (name) + i, "mouse-", 6) == 0 | 6175 | && memcmp (SDATA (name) + i, "mouse-", 6) == 0 |
| 6176 | && ('0' <= SREF (name, i + 6) && SREF (name, i + 6) <= '9')) | 6176 | && ('0' <= SREF (name, i + 6) && SREF (name, i + 6) <= '9')) |
| 6177 | modifiers |= click_modifier; | 6177 | modifiers |= click_modifier; |
| 6178 | 6178 | ||
| 6179 | if (! (modifiers & (double_modifier | triple_modifier)) | 6179 | if (! (modifiers & (double_modifier | triple_modifier)) |
| 6180 | && i + 6 < SBYTES (name) | 6180 | && i + 6 < SBYTES (name) |
| 6181 | && strncmp (SSDATA (name) + i, "wheel-", 6) == 0) | 6181 | && memcmp (SDATA (name) + i, "wheel-", 6) == 0) |
| 6182 | modifiers |= click_modifier; | 6182 | modifiers |= click_modifier; |
| 6183 | 6183 | ||
| 6184 | if (modifier_end) | 6184 | if (modifier_end) |
| @@ -6630,7 +6630,7 @@ parse_solitary_modifier (Lisp_Object symbol) | |||
| 6630 | 6630 | ||
| 6631 | #define MULTI_LETTER_MOD(BIT, NAME, LEN) \ | 6631 | #define MULTI_LETTER_MOD(BIT, NAME, LEN) \ |
| 6632 | if (LEN == SBYTES (name) \ | 6632 | if (LEN == SBYTES (name) \ |
| 6633 | && ! strncmp (SSDATA (name), NAME, LEN)) \ | 6633 | && ! memcmp (SDATA (name), NAME, LEN)) \ |
| 6634 | return BIT; | 6634 | return BIT; |
| 6635 | 6635 | ||
| 6636 | case 'A': | 6636 | case 'A': |
| @@ -7418,7 +7418,7 @@ menu_separator_name_p (const char *label) | |||
| 7418 | if (!label) | 7418 | if (!label) |
| 7419 | return 0; | 7419 | return 0; |
| 7420 | else if (strlen (label) > 3 | 7420 | else if (strlen (label) > 3 |
| 7421 | && strncmp (label, "--", 2) == 0 | 7421 | && memcmp (label, "--", 2) == 0 |
| 7422 | && label[2] != '-') | 7422 | && label[2] != '-') |
| 7423 | { | 7423 | { |
| 7424 | int i; | 7424 | int i; |
diff --git a/src/lread.c b/src/lread.c index bd85e44093e..640414b3e91 100644 --- a/src/lread.c +++ b/src/lread.c | |||
| @@ -1495,26 +1495,14 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes, Lisp_Object *sto | |||
| 1495 | 1495 | ||
| 1496 | /* Concatenate path element/specified name with the suffix. | 1496 | /* Concatenate path element/specified name with the suffix. |
| 1497 | If the directory starts with /:, remove that. */ | 1497 | If the directory starts with /:, remove that. */ |
| 1498 | if (SCHARS (filename) > 2 | 1498 | int prefixlen = ((SCHARS (filename) > 2 |
| 1499 | && SREF (filename, 0) == '/' | 1499 | && SREF (filename, 0) == '/' |
| 1500 | && SREF (filename, 1) == ':') | 1500 | && SREF (filename, 1) == ':') |
| 1501 | { | 1501 | ? 2 : 0); |
| 1502 | fnlen = SBYTES (filename) - 2; | 1502 | fnlen = SBYTES (filename) - prefixlen; |
| 1503 | strncpy (fn, SSDATA (filename) + 2, fnlen); | 1503 | memcpy (fn, SDATA (filename) + prefixlen, fnlen); |
| 1504 | fn[fnlen] = '\0'; | 1504 | memcpy (fn + fnlen, SDATA (XCAR (tail)), lsuffix + 1); |
| 1505 | } | 1505 | fnlen += lsuffix; |
| 1506 | else | ||
| 1507 | { | ||
| 1508 | fnlen = SBYTES (filename); | ||
| 1509 | strncpy (fn, SSDATA (filename), fnlen); | ||
| 1510 | fn[fnlen] = '\0'; | ||
| 1511 | } | ||
| 1512 | |||
| 1513 | if (lsuffix != 0) /* Bug happens on CCI if lsuffix is 0. */ | ||
| 1514 | { | ||
| 1515 | strncat (fn, SSDATA (XCAR (tail)), lsuffix); | ||
| 1516 | fnlen += lsuffix; | ||
| 1517 | } | ||
| 1518 | /* Check that the file exists and is not a directory. */ | 1506 | /* Check that the file exists and is not a directory. */ |
| 1519 | /* We used to only check for handlers on non-absolute file names: | 1507 | /* We used to only check for handlers on non-absolute file names: |
| 1520 | if (absolute) | 1508 | if (absolute) |
diff --git a/src/nsmenu.m b/src/nsmenu.m index cccecffb427..2cd626e131a 100644 --- a/src/nsmenu.m +++ b/src/nsmenu.m | |||
| @@ -426,7 +426,8 @@ ns_update_menubar (struct frame *f, int deep_p, EmacsMenu *submenu) | |||
| 426 | break; | 426 | break; |
| 427 | else | 427 | else |
| 428 | continue; | 428 | continue; |
| 429 | if (strncmp (previous_strings[i], SDATA (string), 10)) | 429 | if (memcmp (previous_strings[i], SDATA (string), |
| 430 | min (10, SBYTES (string) + 1))) | ||
| 430 | break; | 431 | break; |
| 431 | } | 432 | } |
| 432 | 433 | ||
| @@ -447,7 +448,8 @@ ns_update_menubar (struct frame *f, int deep_p, EmacsMenu *submenu) | |||
| 447 | break; | 448 | break; |
| 448 | 449 | ||
| 449 | if (n < 100) | 450 | if (n < 100) |
| 450 | strncpy (previous_strings[i/4], SDATA (string), 10); | 451 | memcpy (previous_strings[i/4], min (10, SBYTES (string) + 1), |
| 452 | SDATA (string)); | ||
| 451 | 453 | ||
| 452 | wv = xmalloc_widget_value (); | 454 | wv = xmalloc_widget_value (); |
| 453 | wv->name = SSDATA (string); | 455 | wv->name = SSDATA (string); |
diff --git a/src/nsterm.m b/src/nsterm.m index fde02f3ec9b..0745efc35bd 100644 --- a/src/nsterm.m +++ b/src/nsterm.m | |||
| @@ -37,6 +37,7 @@ GNUstep port and post-20 update by Adrian Robert (arobert@cogsci.ucsd.edu) | |||
| 37 | #include <unistd.h> | 37 | #include <unistd.h> |
| 38 | #include <setjmp.h> | 38 | #include <setjmp.h> |
| 39 | #include <c-strcase.h> | 39 | #include <c-strcase.h> |
| 40 | #include <ftoastr.h> | ||
| 40 | 41 | ||
| 41 | #include "lisp.h" | 42 | #include "lisp.h" |
| 42 | #include "blockinput.h" | 43 | #include "blockinput.h" |
| @@ -1442,21 +1443,16 @@ ns_get_color (const char *name, NSColor **col) | |||
| 1442 | [scanner scanFloat: &b]; | 1443 | [scanner scanFloat: &b]; |
| 1443 | } | 1444 | } |
| 1444 | else if (!strncmp(name, "rgb:", 4)) /* A newer X11 format -- rgb:r/g/b */ | 1445 | else if (!strncmp(name, "rgb:", 4)) /* A newer X11 format -- rgb:r/g/b */ |
| 1445 | { | 1446 | scaling = (snprintf (hex, sizeof hex, "%s", name + 4) - 2) / 3; |
| 1446 | strncpy (hex, name + 4, 19); | ||
| 1447 | hex[19] = '\0'; | ||
| 1448 | scaling = (strlen(hex) - 2) / 3; | ||
| 1449 | } | ||
| 1450 | else if (name[0] == '#') /* An old X11 format; convert to newer */ | 1447 | else if (name[0] == '#') /* An old X11 format; convert to newer */ |
| 1451 | { | 1448 | { |
| 1452 | int len = (strlen(name) - 1); | 1449 | int len = (strlen(name) - 1); |
| 1453 | int start = (len % 3 == 0) ? 1 : len / 4 + 1; | 1450 | int start = (len % 3 == 0) ? 1 : len / 4 + 1; |
| 1454 | int i; | 1451 | int i; |
| 1455 | scaling = strlen(name+start) / 3; | 1452 | scaling = strlen(name+start) / 3; |
| 1456 | for (i=0; i<3; i++) { | 1453 | for (i = 0; i < 3; i++) |
| 1457 | strncpy(hex + i * (scaling + 1), name + start + i * scaling, scaling); | 1454 | snprintf (hex + i * (scaling + 1), "%.*s/", scaling, |
| 1458 | hex[(i+1) * (scaling + 1) - 1] = '/'; | 1455 | name + start + i * scaling); |
| 1459 | } | ||
| 1460 | hex[3 * (scaling + 1) - 1] = '\0'; | 1456 | hex[3 * (scaling + 1) - 1] = '\0'; |
| 1461 | } | 1457 | } |
| 1462 | 1458 | ||
| @@ -4107,10 +4103,7 @@ ns_term_init (Lisp_Object display_name) | |||
| 4107 | ns_display_name_list); | 4103 | ns_display_name_list); |
| 4108 | dpyinfo->name_list_element = XCAR (ns_display_name_list); | 4104 | dpyinfo->name_list_element = XCAR (ns_display_name_list); |
| 4109 | 4105 | ||
| 4110 | /* Set the name of the terminal. */ | 4106 | terminal->name = xstrdup (SSDATA (display_name)); |
| 4111 | terminal->name = xmalloc (SBYTES (display_name) + 1); | ||
| 4112 | strncpy (terminal->name, SDATA (display_name), SBYTES (display_name)); | ||
| 4113 | terminal->name[SBYTES (display_name)] = 0; | ||
| 4114 | 4107 | ||
| 4115 | UNBLOCK_INPUT; | 4108 | UNBLOCK_INPUT; |
| 4116 | 4109 | ||
| @@ -4167,14 +4160,14 @@ ns_term_init (Lisp_Object display_name) | |||
| 4167 | } | 4160 | } |
| 4168 | 4161 | ||
| 4169 | { | 4162 | { |
| 4170 | char c[128]; | ||
| 4171 | #ifdef NS_IMPL_GNUSTEP | 4163 | #ifdef NS_IMPL_GNUSTEP |
| 4172 | strncpy (c, gnustep_base_version, sizeof (c)); | 4164 | Vwindow_system_version = build_string (gnustep_base_version); |
| 4173 | #else | 4165 | #else |
| 4174 | /*PSnextrelease (128, c); */ | 4166 | /*PSnextrelease (128, c); */ |
| 4175 | snprintf (c, sizeof (c), "%g", NSAppKitVersionNumber); | 4167 | char c[DBL_BUFSIZE_BOUND]; |
| 4168 | int len = dtoastr (c, sizeof c, 0, 0, NSAppKitVersionNumber); | ||
| 4169 | Vwindow_system_version = make_unibyte_string (c, len); | ||
| 4176 | #endif | 4170 | #endif |
| 4177 | Vwindow_system_version = build_string (c); | ||
| 4178 | } | 4171 | } |
| 4179 | 4172 | ||
| 4180 | delete_keyboard_wait_descriptor (0); | 4173 | delete_keyboard_wait_descriptor (0); |
diff --git a/src/process.c b/src/process.c index b8c3a18b33d..79100eb7a2c 100644 --- a/src/process.c +++ b/src/process.c | |||
| @@ -3013,7 +3013,9 @@ usage: (make-network-process &rest ARGS) */) | |||
| 3013 | CHECK_STRING (service); | 3013 | CHECK_STRING (service); |
| 3014 | memset (&address_un, 0, sizeof address_un); | 3014 | memset (&address_un, 0, sizeof address_un); |
| 3015 | address_un.sun_family = AF_LOCAL; | 3015 | address_un.sun_family = AF_LOCAL; |
| 3016 | strncpy (address_un.sun_path, SSDATA (service), sizeof address_un.sun_path); | 3016 | if (sizeof address_un.sun_path <= SBYTES (service)) |
| 3017 | error ("Service name too long"); | ||
| 3018 | strcpy (address_un.sun_path, SSDATA (service)); | ||
| 3017 | ai.ai_addr = (struct sockaddr *) &address_un; | 3019 | ai.ai_addr = (struct sockaddr *) &address_un; |
| 3018 | ai.ai_addrlen = sizeof address_un; | 3020 | ai.ai_addrlen = sizeof address_un; |
| 3019 | goto open_socket; | 3021 | goto open_socket; |
| @@ -3717,8 +3719,9 @@ FLAGS is the current flags of the interface. */) | |||
| 3717 | 3719 | ||
| 3718 | CHECK_STRING (ifname); | 3720 | CHECK_STRING (ifname); |
| 3719 | 3721 | ||
| 3720 | memset (rq.ifr_name, 0, sizeof rq.ifr_name); | 3722 | if (sizeof rq.ifr_name <= SBYTES (ifname)) |
| 3721 | strncpy (rq.ifr_name, SSDATA (ifname), sizeof (rq.ifr_name)); | 3723 | error ("interface name too long"); |
| 3724 | strcpy (rq.ifr_name, SSDATA (ifname)); | ||
| 3722 | 3725 | ||
| 3723 | s = socket (AF_INET, SOCK_STREAM, 0); | 3726 | s = socket (AF_INET, SOCK_STREAM, 0); |
| 3724 | if (s < 0) | 3727 | if (s < 0) |
diff --git a/src/regex.c b/src/regex.c index 751006d57ba..4bf119402ac 100644 --- a/src/regex.c +++ b/src/regex.c | |||
| @@ -6644,7 +6644,7 @@ regerror (int err_code, const regex_t *preg, char *errbuf, size_t errbuf_size) | |||
| 6644 | { | 6644 | { |
| 6645 | if (msg_size > errbuf_size) | 6645 | if (msg_size > errbuf_size) |
| 6646 | { | 6646 | { |
| 6647 | strncpy (errbuf, msg, errbuf_size - 1); | 6647 | memcpy (errbuf, msg, errbuf_size - 1); |
| 6648 | errbuf[errbuf_size - 1] = 0; | 6648 | errbuf[errbuf_size - 1] = 0; |
| 6649 | } | 6649 | } |
| 6650 | else | 6650 | else |
diff --git a/src/s/gnu-linux.h b/src/s/gnu-linux.h index e3d43249d81..6f45ee00b78 100644 --- a/src/s/gnu-linux.h +++ b/src/s/gnu-linux.h | |||
| @@ -63,8 +63,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 63 | close (fd); \ | 63 | close (fd); \ |
| 64 | return -1; \ | 64 | return -1; \ |
| 65 | } \ | 65 | } \ |
| 66 | strncpy (pty_name, ptyname, sizeof (pty_name)); \ | 66 | snprintf (pty_name, sizeof pty_name, "%s", ptyname); \ |
| 67 | pty_name[sizeof (pty_name) - 1] = 0; \ | ||
| 68 | sigunblock (sigmask (SIGCHLD)); \ | 67 | sigunblock (sigmask (SIGCHLD)); \ |
| 69 | } | 68 | } |
| 70 | 69 | ||
diff --git a/src/s/sol2-6.h b/src/s/sol2-6.h index bb7a9859b7d..ec45748e03a 100644 --- a/src/s/sol2-6.h +++ b/src/s/sol2-6.h | |||
| @@ -54,8 +54,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 54 | { emacs_close (fd); return -1; } \ | 54 | { emacs_close (fd); return -1; } \ |
| 55 | if (!(ptyname = ptsname (fd))) \ | 55 | if (!(ptyname = ptsname (fd))) \ |
| 56 | { emacs_close (fd); return -1; } \ | 56 | { emacs_close (fd); return -1; } \ |
| 57 | strncpy (pty_name, ptyname, sizeof (pty_name)); \ | 57 | snprintf (pty_name, sizeof pty_name, "%s", ptyname); \ |
| 58 | pty_name[sizeof (pty_name) - 1] = 0; \ | ||
| 59 | } | 58 | } |
| 60 | 59 | ||
| 61 | #define GC_SETJMP_WORKS 1 | 60 | #define GC_SETJMP_WORKS 1 |
diff --git a/src/s/unixware.h b/src/s/unixware.h index e9ebb63f30a..5bda987ffe1 100644 --- a/src/s/unixware.h +++ b/src/s/unixware.h | |||
| @@ -40,8 +40,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 40 | fatal("could not unlock slave pty"); \ | 40 | fatal("could not unlock slave pty"); \ |
| 41 | if (!(ptyname = ptsname(fd))) \ | 41 | if (!(ptyname = ptsname(fd))) \ |
| 42 | fatal ("could not enable slave pty"); \ | 42 | fatal ("could not enable slave pty"); \ |
| 43 | strncpy(pty_name, ptyname, sizeof(pty_name)); \ | 43 | snprintf (pty_name, sizeof pty_name, "%s", ptyname); \ |
| 44 | pty_name[sizeof(pty_name) - 1] = 0; \ | ||
| 45 | } | 44 | } |
| 46 | 45 | ||
| 47 | /* Conservative garbage collection has not been tested, so for now | 46 | /* Conservative garbage collection has not been tested, so for now |
diff --git a/src/sysdep.c b/src/sysdep.c index 0639b72285a..ed926760414 100644 --- a/src/sysdep.c +++ b/src/sysdep.c | |||
| @@ -2744,9 +2744,11 @@ system_process_attributes (Lisp_Object pid) | |||
| 2744 | char procbuf[1025], *p, *q; | 2744 | char procbuf[1025], *p, *q; |
| 2745 | int fd; | 2745 | int fd; |
| 2746 | ssize_t nread; | 2746 | ssize_t nread; |
| 2747 | const char *cmd = NULL; | 2747 | static char const default_cmd[] = "???"; |
| 2748 | const char *cmd = default_cmd; | ||
| 2749 | int cmdsize = sizeof default_cmd - 1; | ||
| 2748 | char *cmdline = NULL; | 2750 | char *cmdline = NULL; |
| 2749 | ptrdiff_t cmdsize = 0, cmdline_size; | 2751 | ptrdiff_t cmdline_size; |
| 2750 | unsigned char c; | 2752 | unsigned char c; |
| 2751 | printmax_t proc_id; | 2753 | printmax_t proc_id; |
| 2752 | int ppid, pgrp, sess, tty, tpgid, thcount; | 2754 | int ppid, pgrp, sess, tty, tpgid, thcount; |
| @@ -2808,11 +2810,6 @@ system_process_attributes (Lisp_Object pid) | |||
| 2808 | } | 2810 | } |
| 2809 | else | 2811 | else |
| 2810 | q = NULL; | 2812 | q = NULL; |
| 2811 | if (cmd == NULL) | ||
| 2812 | { | ||
| 2813 | cmd = "???"; | ||
| 2814 | cmdsize = 3; | ||
| 2815 | } | ||
| 2816 | /* Command name is encoded in locale-coding-system; decode it. */ | 2813 | /* Command name is encoded in locale-coding-system; decode it. */ |
| 2817 | cmd_str = make_unibyte_string (cmd, cmdsize); | 2814 | cmd_str = make_unibyte_string (cmd, cmdsize); |
| 2818 | decoded_cmd = code_convert_string_norecord (cmd_str, | 2815 | decoded_cmd = code_convert_string_norecord (cmd_str, |
| @@ -2950,14 +2947,9 @@ system_process_attributes (Lisp_Object pid) | |||
| 2950 | } | 2947 | } |
| 2951 | if (!cmdline_size) | 2948 | if (!cmdline_size) |
| 2952 | { | 2949 | { |
| 2953 | if (!cmd) | ||
| 2954 | cmd = "???"; | ||
| 2955 | if (!cmdsize) | ||
| 2956 | cmdsize = strlen (cmd); | ||
| 2957 | cmdline_size = cmdsize + 2; | 2950 | cmdline_size = cmdsize + 2; |
| 2958 | cmdline = xmalloc (cmdline_size + 1); | 2951 | cmdline = xmalloc (cmdline_size + 1); |
| 2959 | strcpy (cmdline, "["); | 2952 | sprintf (cmdline, "[%.*s]", cmdsize, cmd); |
| 2960 | strcat (strncat (cmdline, cmd, cmdsize), "]"); | ||
| 2961 | } | 2953 | } |
| 2962 | emacs_close (fd); | 2954 | emacs_close (fd); |
| 2963 | /* Command line is encoded in locale-coding-system; decode it. */ | 2955 | /* Command line is encoded in locale-coding-system; decode it. */ |
diff --git a/src/widget.c b/src/widget.c index e219c200e00..b94c30f4e9c 100644 --- a/src/widget.c +++ b/src/widget.c | |||
| @@ -429,25 +429,15 @@ set_frame_size (EmacsFrame ew) | |||
| 429 | { | 429 | { |
| 430 | /* the tricky things with the sign is to make sure that | 430 | /* the tricky things with the sign is to make sure that |
| 431 | -0 is printed -0. */ | 431 | -0 is printed -0. */ |
| 432 | int len; | ||
| 433 | char *tem; | ||
| 434 | sprintf (shell_position, "=%c%d%c%d", | 432 | sprintf (shell_position, "=%c%d%c%d", |
| 435 | flags & XNegative ? '-' : '+', x < 0 ? -x : x, | 433 | flags & XNegative ? '-' : '+', x < 0 ? -x : x, |
| 436 | flags & YNegative ? '-' : '+', y < 0 ? -y : y); | 434 | flags & YNegative ? '-' : '+', y < 0 ? -y : y); |
| 437 | len = strlen (shell_position) + 1; | 435 | XtVaSetValues (wmshell, XtNgeometry, xstrdup (shell_position), NULL); |
| 438 | tem = xmalloc (len); | ||
| 439 | strncpy (tem, shell_position, len); | ||
| 440 | XtVaSetValues (wmshell, XtNgeometry, tem, NULL); | ||
| 441 | } | 436 | } |
| 442 | else if (flags & (WidthValue | HeightValue)) | 437 | else if (flags & (WidthValue | HeightValue)) |
| 443 | { | 438 | { |
| 444 | int len; | ||
| 445 | char *tem; | ||
| 446 | sprintf (shell_position, "=%dx%d", pixel_width, pixel_height); | 439 | sprintf (shell_position, "=%dx%d", pixel_width, pixel_height); |
| 447 | len = strlen (shell_position) + 1; | 440 | XtVaSetValues (wmshell, XtNgeometry, xstrdup (shell_position), NULL); |
| 448 | tem = xmalloc (len); | ||
| 449 | strncpy (tem, shell_position, len); | ||
| 450 | XtVaSetValues (wmshell, XtNgeometry, tem, NULL); | ||
| 451 | } | 441 | } |
| 452 | 442 | ||
| 453 | /* If the geometry spec we're using has W/H components, mark the size | 443 | /* If the geometry spec we're using has W/H components, mark the size |
diff --git a/src/xdisp.c b/src/xdisp.c index 1732e3dfe56..4c9f3fda0a8 100644 --- a/src/xdisp.c +++ b/src/xdisp.c | |||
| @@ -12492,23 +12492,21 @@ static void debug_method_add (struct window *, char const *, ...) | |||
| 12492 | static void | 12492 | static void |
| 12493 | debug_method_add (struct window *w, char const *fmt, ...) | 12493 | debug_method_add (struct window *w, char const *fmt, ...) |
| 12494 | { | 12494 | { |
| 12495 | char buffer[512]; | ||
| 12496 | char *method = w->desired_matrix->method; | 12495 | char *method = w->desired_matrix->method; |
| 12497 | int len = strlen (method); | 12496 | int len = strlen (method); |
| 12498 | int size = sizeof w->desired_matrix->method; | 12497 | int size = sizeof w->desired_matrix->method; |
| 12499 | int remaining = size - len - 1; | 12498 | int remaining = size - len - 1; |
| 12500 | va_list ap; | 12499 | va_list ap; |
| 12501 | 12500 | ||
| 12502 | va_start (ap, fmt); | ||
| 12503 | vsprintf (buffer, fmt, ap); | ||
| 12504 | va_end (ap); | ||
| 12505 | if (len && remaining) | 12501 | if (len && remaining) |
| 12506 | { | 12502 | { |
| 12507 | method[len] = '|'; | 12503 | method[len] = '|'; |
| 12508 | --remaining, ++len; | 12504 | --remaining, ++len; |
| 12509 | } | 12505 | } |
| 12510 | 12506 | ||
| 12511 | strncpy (method + len, buffer, remaining); | 12507 | va_start (ap, fmt); |
| 12508 | vsnprintf (method + len, remaining + 1, fmt, ap); | ||
| 12509 | va_end (ap); | ||
| 12512 | 12510 | ||
| 12513 | if (trace_redisplay_p) | 12511 | if (trace_redisplay_p) |
| 12514 | fprintf (stderr, "%p (%s): %s\n", | 12512 | fprintf (stderr, "%p (%s): %s\n", |
| @@ -12517,7 +12515,7 @@ debug_method_add (struct window *w, char const *fmt, ...) | |||
| 12517 | && STRINGP (BVAR (XBUFFER (w->buffer), name))) | 12515 | && STRINGP (BVAR (XBUFFER (w->buffer), name))) |
| 12518 | ? SSDATA (BVAR (XBUFFER (w->buffer), name)) | 12516 | ? SSDATA (BVAR (XBUFFER (w->buffer), name)) |
| 12519 | : "no buffer"), | 12517 | : "no buffer"), |
| 12520 | buffer); | 12518 | method + len); |
| 12521 | } | 12519 | } |
| 12522 | 12520 | ||
| 12523 | #endif /* GLYPH_DEBUG */ | 12521 | #endif /* GLYPH_DEBUG */ |