+2012-07-10 Paul Eggert <eggert@cs.ucla.edu>
+
+ Simplify by avoiding confusing use of strncpy etc.
+ * etags.c (write_classname, C_entries):
+ Use sprintf rather than strncpy or strncat.
+ * etags.c (consider_token, C_entries, HTML_labels, Prolog_functions)
+ (Erlang_functions, substitute, readline_internal, savenstr):
+ * movemail.c (mail_spool_name):
+ Use memcpy rather than strncpy or strncat when either will do.
+ * make-docfile.c (write_c_args):
+ Use memcmp rather than strncmp when either will do.
+ * movemail.c (pop_retr):
+ * pop.c (pop_stat, pop_list, pop_multi_first, pop_last)
+ (socket_connection, pop_getline, sendline, getok):
+ Use snprintf rather than strncpy or strncat.
+ * movemail.c (concat): Remove; no longer needed.
+ (xmalloc): Define only if needed, now that concat has gone away.
+ Return void *. All uses changed.
+
2012-07-09 Paul Eggert <eggert@cs.ucla.edu>
Add GCC-style 'const' attribute to functions that can use it.
}
for (i = 1; i < cstack.nl; i++)
{
- char *s;
- int slen;
-
- s = cstack.cname[i];
+ char *s = cstack.cname[i];
if (s == NULL)
continue;
- slen = strlen (s);
- len += slen + qlen;
- linebuffer_setlen (cn, len);
- strncat (cn->buffer, qualifier, qlen);
- strncat (cn->buffer, s, slen);
+ linebuffer_setlen (cn, len + qlen + strlen (s));
+ len += sprintf (cn->buffer + len, "%s%s", qualifier, s);
}
}
fvdef = fvnone;
objdef = omethodtag;
linebuffer_setlen (&token_name, len);
- strncpy (token_name.buffer, str, len);
+ memcpy (token_name.buffer, str, len);
token_name.buffer[len] = '\0';
return TRUE;
}
case omethodparm:
if (parlev == 0)
{
+ int oldlen = token_name.len;
fvdef = fvnone;
objdef = omethodtag;
- linebuffer_setlen (&token_name, token_name.len + len);
- strncat (token_name.buffer, str, len);
+ linebuffer_setlen (&token_name, oldlen + len);
+ memcpy (token_name.buffer + oldlen, str, len);
return TRUE;
}
return FALSE;
&& nestlev > 0 && definedef == dnone)
/* in struct body */
{
+ int len;
write_classname (&token_name, qualifier);
- linebuffer_setlen (&token_name,
- token_name.len+qlen+toklen);
- strcat (token_name.buffer, qualifier);
- strncat (token_name.buffer,
- newlb.buffer + tokoff, toklen);
+ len = token_name.len;
+ linebuffer_setlen (&token_name, len+qlen+toklen);
+ sprintf (token_name.buffer + len, "%s%.*s",
+ qualifier, toklen, newlb.buffer + tokoff);
token.named = TRUE;
}
else if (objdef == ocatseen)
{
int len = strlen (objtag) + 2 + toklen;
linebuffer_setlen (&token_name, len);
- strcpy (token_name.buffer, objtag);
- strcat (token_name.buffer, "(");
- strncat (token_name.buffer,
- newlb.buffer + tokoff, toklen);
- strcat (token_name.buffer, ")");
+ sprintf (token_name.buffer, "%s(%.*s)",
+ objtag, toklen, newlb.buffer + tokoff);
token.named = TRUE;
}
else if (objdef == omethodtag
len -= 1;
}
linebuffer_setlen (&token_name, len);
- strncpy (token_name.buffer,
- newlb.buffer + off, len);
+ memcpy (token_name.buffer,
+ newlb.buffer + off, len);
token_name.buffer[len] = '\0';
if (defun)
while (--len >= 0)
else
{
linebuffer_setlen (&token_name, toklen);
- strncpy (token_name.buffer,
- newlb.buffer + tokoff, toklen);
+ memcpy (token_name.buffer,
+ newlb.buffer + tokoff, toklen);
token_name.buffer[toklen] = '\0';
/* Name macros and members. */
token.named = (structdef == stagseen
for (end = dbp; *end != '\0' && intoken (*end); end++)
continue;
linebuffer_setlen (&token_name, end - dbp);
- strncpy (token_name.buffer, dbp, end - dbp);
+ memcpy (token_name.buffer, dbp, end - dbp);
token_name.buffer[end - dbp] = '\0';
dbp = end;
else if (len + 1 > allocated)
xrnew (last, len + 1, char);
allocated = len + 1;
- strncpy (last, cp, len);
+ memcpy (last, cp, len);
last[len] = '\0';
}
}
else if (len + 1 > allocated)
xrnew (last, len + 1, char);
allocated = len + 1;
- strncpy (last, cp, len);
+ memcpy (last, cp, len);
last[len] = '\0';
}
}
{
dig = *out - '0';
diglen = regs->end[dig] - regs->start[dig];
- strncpy (t, in + regs->start[dig], diglen);
+ memcpy (t, in + regs->start[dig], diglen);
t += diglen;
}
else
filebuf.size *= 2;
xrnew (filebuf.buffer, filebuf.size, char);
}
- strncpy (filebuf.buffer + filebuf.len, lbp->buffer, lbp->len);
+ memcpy (filebuf.buffer + filebuf.len, lbp->buffer, lbp->len);
filebuf.len += lbp->len;
filebuf.buffer[filebuf.len++] = '\n';
filebuf.buffer[filebuf.len] = '\0';
register char *dp;
dp = xnew (len + 1, char);
- strncpy (dp, cp, len);
+ memcpy (dp, cp, len);
dp[len] = '\0';
return dp;
}
/* In C code, `default' is a reserved word, so we spell it
`defalt'; demangle that here. */
- if (ident_length == 6 && strncmp (ident_start, "defalt", 6) == 0)
+ if (ident_length == 6 && memcmp (ident_start, "defalt", 6) == 0)
fprintf (out, "DEFAULT");
else
while (ident_length-- > 0)
static void error (const char *s1, const char *s2, const char *s3);
static _Noreturn void pfatal_with_name (char *name);
static _Noreturn void pfatal_and_delete (char *name);
-static char *concat (const char *s1, const char *s2, const char *s3);
-static long *xmalloc (unsigned int size);
+#ifdef MAIL_USE_MAILLOCK
+static void *xmalloc (size_t size);
+#endif
#ifdef MAIL_USE_POP
static int popmail (char *mailbox, char *outfile, int preserve, char *password, int reverse_order);
static int pop_retr (popserver server, int msgno, FILE *arg);
inname_dirlen && !IS_DIRECTORY_SEP (inname[inname_dirlen - 1]);
inname_dirlen--)
continue;
- tempname = (char *) xmalloc (inname_dirlen + sizeof "EXXXXXX");
+ tempname = xmalloc (inname_dirlen + sizeof "EXXXXXX");
while (1)
{
if (stat (MAILDIR, &stat1) < 0)
return NULL;
- indir = (char *) xmalloc (fname - inname + 1);
- strncpy (indir, inname, fname - inname);
+ indir = xmalloc (fname - inname + 1);
+ memcpy (indir, inname, fname - inname);
indir[fname-inname] = '\0';
fatal ("%s for %s", s, name);
}
-/* Return a newly-allocated string whose contents concatenate those of s1, s2, s3. */
-
-static char *
-concat (const char *s1, const char *s2, const char *s3)
-{
- size_t len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3);
- char *result = (char *) xmalloc (len1 + len2 + len3 + 1);
-
- strcpy (result, s1);
- strcpy (result + len1, s2);
- strcpy (result + len1 + len2, s3);
- *(result + len1 + len2 + len3) = 0;
-
- return result;
-}
-
+#ifdef MAIL_USE_MAILLOCK
/* Like malloc but get fatal error if memory is exhausted. */
-static long *
-xmalloc (unsigned int size)
+static void *
+xmalloc (size_t size)
{
- long *result = (long *) malloc (size);
+ void *result = malloc (size);
if (!result)
fatal ("virtual memory exhausted", 0, 0);
return result;
}
+#endif
\f
/* This is the guts of the interface to the Post Office Protocol. */
if (pop_retrieve_first (server, msgno, &line))
{
- char *msg = concat ("Error from POP server: ", pop_error, "");
- strncpy (Errmsg, msg, sizeof (Errmsg));
- Errmsg[sizeof (Errmsg)-1] = '\0';
- free (msg);
+ snprintf (Errmsg, sizeof Errmsg, "Error from POP server: %s", pop_error);
return (NOTOK);
}
if (ret)
{
- char *msg = concat ("Error from POP server: ", pop_error, "");
- strncpy (Errmsg, msg, sizeof (Errmsg));
- Errmsg[sizeof (Errmsg)-1] = '\0';
- free (msg);
+ snprintf (Errmsg, sizeof Errmsg, "Error from POP server: %s", pop_error);
return (NOTOK);
}
if (strncmp (fromserver, "+OK ", 4))
{
if (0 == strncmp (fromserver, "-ERR", 4))
- {
- strncpy (pop_error, fromserver, ERROR_MAX);
- pop_error[ERROR_MAX-1] = '\0';
- }
+ snprintf (pop_error, ERROR_MAX, "%s", fromserver);
else
{
strcpy (pop_error,
if (strncmp (fromserver, "+OK ", 4))
{
if (! strncmp (fromserver, "-ERR", 4))
- {
- strncpy (pop_error, fromserver, ERROR_MAX);
- pop_error[ERROR_MAX-1] = '\0';
- }
+ snprintf (pop_error, ERROR_MAX, "%s", fromserver);
else
{
strcpy (pop_error,
if (0 == strncmp (*response, "-ERR", 4))
{
- strncpy (pop_error, *response, ERROR_MAX);
- pop_error[ERROR_MAX-1] = '\0';
+ snprintf (pop_error, ERROR_MAX, "%s", *response);
return (-1);
}
else if (0 == strncmp (*response, "+OK", 3))
if (! strncmp (fromserver, "-ERR", 4))
{
- strncpy (pop_error, fromserver, ERROR_MAX);
- pop_error[ERROR_MAX-1] = '\0';
+ snprintf (pop_error, ERROR_MAX, "%s", fromserver);
return (-1);
}
else if (strncmp (fromserver, "+OK ", 4))
sock = socket (PF_INET, SOCK_STREAM, 0);
if (sock < 0)
{
- strcpy (pop_error, POP_SOCKET_ERROR);
- strncat (pop_error, strerror (errno),
- ERROR_MAX - sizeof (POP_SOCKET_ERROR));
+ snprintf (pop_error, ERROR_MAX, "%s%s",
+ POP_SOCKET_ERROR, strerror (errno));
return (-1);
}
if (! connect_ok)
{
CLOSESOCKET (sock);
- strcpy (pop_error, CONNECT_ERROR);
- strncat (pop_error, strerror (errno),
- ERROR_MAX - sizeof (CONNECT_ERROR));
+ snprintf (pop_error, ERROR_MAX, "%s%s", CONNECT_ERROR, strerror (errno));
return (-1);
}
krb5_auth_con_free (kcontext, auth_context);
if (kcontext)
krb5_free_context (kcontext);
- strcpy (pop_error, KRB_ERROR);
- strncat (pop_error, error_message (rem),
- ERROR_MAX - sizeof (KRB_ERROR));
+ snprintf (pop_error, ERROR_MAX, "%s%s",
+ KRB_ERROR, error_message (rem));
CLOSESOCKET (sock);
return (-1);
}
krb5_free_principal (kcontext, server);
if (rem)
{
- strcpy (pop_error, KRB_ERROR);
- strncat (pop_error, error_message (rem),
- ERROR_MAX - sizeof (KRB_ERROR));
+ int pop_error_len = snprintf (pop_error, ERROR_MAX, "%s%s",
+ KRB_ERROR, error_message (rem));
#if defined HAVE_KRB5_ERROR_TEXT
if (err_ret && err_ret->text.length)
{
- strncat (pop_error, " [server says '",
- ERROR_MAX - strlen (pop_error) - 1);
- strncat (pop_error, err_ret->text.data,
- min (ERROR_MAX - strlen (pop_error) - 1,
- err_ret->text.length));
- strncat (pop_error, "']",
- ERROR_MAX - strlen (pop_error) - 1);
+ int errlen = err_ret->text.length;
+ snprintf (pop_error + pop_error_len, ERROR_MAX - pop_error_len,
+ " [server says '.*%s']", errlen, err_ret->text.data);
}
#elif defined HAVE_KRB5_ERROR_E_TEXT
- if (err_ret && err_ret->e_text && strlen (*err_ret->e_text))
- {
- strncat (pop_error, " [server says '",
- ERROR_MAX - strlen (pop_error) - 1);
- strncat (pop_error, *err_ret->e_text,
- ERROR_MAX - strlen (pop_error) - 1);
- strncat (pop_error, "']",
- ERROR_MAX - strlen (pop_error) - 1);
- }
+ if (err_ret && err_ret->e_text && **err_ret->e_text)
+ snprintf (pop_error + pop_error_len, ERRMAX - pop_error_len,
+ " [server says '%s']", *err_ret->e_text);
#endif
if (err_ret)
krb5_free_error (kcontext, err_ret);
free ((char *) ticket);
if (rem != KSUCCESS)
{
- strcpy (pop_error, KRB_ERROR);
- strncat (pop_error, krb_err_txt[rem],
- ERROR_MAX - sizeof (KRB_ERROR));
+ snprintf (pop_error, ERROR_MAX, "%s%s", KRB_ERROR, krb_err_txt[rem]);
CLOSESOCKET (sock);
return (-1);
}
server->buffer_size - server->data - 1, 0);
if (ret < 0)
{
- strcpy (pop_error, GETLINE_ERROR);
- strncat (pop_error, strerror (errno),
- ERROR_MAX - sizeof (GETLINE_ERROR));
+ snprintf (pop_error, ERROR_MAX, "%s%s",
+ GETLINE_ERROR, strerror (errno));
pop_trash (server);
return (-1);
}
if (ret < 0)
{
pop_trash (server);
- strcpy (pop_error, SENDLINE_ERROR);
- strncat (pop_error, strerror (errno),
- ERROR_MAX - sizeof (SENDLINE_ERROR));
+ snprintf (pop_error, ERROR_MAX, "%s%s", SENDLINE_ERROR, strerror (errno));
return (ret);
}
return (0);
else if (! strncmp (fromline, "-ERR", 4))
{
- strncpy (pop_error, fromline, ERROR_MAX);
- pop_error[ERROR_MAX-1] = '\0';
+ snprintf (pop_error, ERROR_MAX, "%s", fromline);
return (-1);
}
else
+2012-07-10 Paul Eggert <eggert@cs.ucla.edu>
+
+ Simplify by avoiding confusing use of strncpy etc.
+ * doc.c (Fsnarf_documentation):
+ * fileio.c (Ffile_name_directory, Fsubstitute_in_file_name):
+ * frame.c (Fmake_terminal_frame):
+ * gtkutil.c (get_utf8_string):
+ * lread.c (openp):
+ * nsmenu.m (ns_update_menubar):
+ * regex.c (regerror):
+ Prefer memcpy to strncpy and strncat when either will do.
+ * fileio.c (Fsubstitute_in_file_name):
+ * keyboard.c (MULTI_LETTER_MOD, parse_modifiers_uncached)
+ (menu_separator_name_p):
+ * nsmenu.m (ns_update_menubar):
+ Prefer memcmp to strncmp when either will do.
+ * nsterm.m: Include <ftoastr.h>.
+ (ns_get_color):
+ * s/gnu-linux.h, s/sol2-6.h, s/unixware.h (PTY_TTY_NAME_SPRINTF):
+ Prefer snprintf to strncpy.
+ * nsterm.m (ns_term_init):
+ * widget.c (set_frame_size) [0]: Prefer xstrdup to xmalloc + strncpy.
+ * nsterm.m (ns_term_init):
+ Avoid the need for strncpy, by using build_string or
+ make_unibyte_string directly. Use dtoastr, not snprintf.
+ * process.c (Fmake_network_process): Diagnose service names that
+ are too long, rather than silently truncating them or creating
+ non-null-terminated names.
+ (Fnetwork_interface_info): Likewise, for interface names.
+ * sysdep.c (system_process_attributes) [GNU_LINUX]:
+ Prefer sprintf to strncat.
+ * xdisp.c (debug_method_add) [GLYPH_DEBUG]:
+ Prefer vsnprintf to vsprintf + strncpy.
+
2012-07-10 Glenn Morris <rgm@gnu.org>
* dispnew.c (PENDING_OUTPUT_COUNT) [!__GNU_LIBRARY__]:
{
ptrdiff_t len = end - p - 2;
char *fromfile = alloca (len + 1);
- strncpy (fromfile, &p[2], len);
+ memcpy (fromfile, &p[2], len);
fromfile[len] = 0;
if (fromfile[len-1] == 'c')
fromfile[len-1] = 'o';
if (p == beg + 4 && IS_DIRECTORY_SEP (*beg) && beg[1] == ':')
{
- strncpy (res, beg, 2);
+ memcpy (res, beg, 2);
beg += 2;
r += 2;
}
/* Copy out the variable name. */
target = alloca (s - o + 1);
- strncpy (target, o, s - o);
+ memcpy (target, o, s - o);
target[s - o] = 0;
#ifdef DOS_NT
strupr (target); /* $home == $HOME etc. */
/* Copy out the variable name. */
target = alloca (s - o + 1);
- strncpy (target, o, s - o);
+ memcpy (target, o, s - o);
target[s - o] = 0;
#ifdef DOS_NT
strupr (target); /* $home == $HOME etc. */
orig = make_unibyte_string (o, orig_length);
decoded = DECODE_FILE (orig);
decoded_length = SBYTES (decoded);
- strncpy (x, SSDATA (decoded), decoded_length);
+ memcpy (x, SDATA (decoded), decoded_length);
x += decoded_length;
/* If environment variable needed decoding, return value
needs to be multibyte. */
if (decoded_length != orig_length
- || strncmp (SSDATA (decoded), o, orig_length))
+ || memcmp (SDATA (decoded), o, orig_length))
multibyte = 1;
}
}
if (!NILP (tty))
{
name = alloca (SBYTES (tty) + 1);
- strncpy (name, SSDATA (tty), SBYTES (tty));
+ memcpy (name, SSDATA (tty), SBYTES (tty));
name[SBYTES (tty)] = 0;
}
if (!NILP (tty_type))
{
type = alloca (SBYTES (tty_type) + 1);
- strncpy (type, SSDATA (tty_type), SBYTES (tty_type));
+ memcpy (type, SSDATA (tty_type), SBYTES (tty_type));
type[SBYTES (tty_type)] = 0;
}
&bytes_written, &err))
&& err->code == G_CONVERT_ERROR_ILLEGAL_SEQUENCE)
{
- strncpy (up, (char *)p, bytes_written);
+ memcpy (up, p, bytes_written);
sprintf (up + bytes_written, "\\%03o", p[bytes_written]);
up += bytes_written+4;
p += bytes_written+1;
#define MULTI_LETTER_MOD(BIT, NAME, LEN) \
if (i + LEN + 1 <= SBYTES (name) \
- && ! strncmp (SSDATA (name) + i, NAME, LEN)) \
+ && ! memcmp (SDATA (name) + i, NAME, LEN)) \
{ \
this_mod_end = i + LEN; \
this_mod = BIT; \
if (! (modifiers & (down_modifier | drag_modifier
| double_modifier | triple_modifier))
&& i + 7 == SBYTES (name)
- && strncmp (SSDATA (name) + i, "mouse-", 6) == 0
+ && memcmp (SDATA (name) + i, "mouse-", 6) == 0
&& ('0' <= SREF (name, i + 6) && SREF (name, i + 6) <= '9'))
modifiers |= click_modifier;
if (! (modifiers & (double_modifier | triple_modifier))
&& i + 6 < SBYTES (name)
- && strncmp (SSDATA (name) + i, "wheel-", 6) == 0)
+ && memcmp (SDATA (name) + i, "wheel-", 6) == 0)
modifiers |= click_modifier;
if (modifier_end)
#define MULTI_LETTER_MOD(BIT, NAME, LEN) \
if (LEN == SBYTES (name) \
- && ! strncmp (SSDATA (name), NAME, LEN)) \
+ && ! memcmp (SDATA (name), NAME, LEN)) \
return BIT;
case 'A':
if (!label)
return 0;
else if (strlen (label) > 3
- && strncmp (label, "--", 2) == 0
+ && memcmp (label, "--", 2) == 0
&& label[2] != '-')
{
int i;
/* Concatenate path element/specified name with the suffix.
If the directory starts with /:, remove that. */
- if (SCHARS (filename) > 2
- && SREF (filename, 0) == '/'
- && SREF (filename, 1) == ':')
- {
- fnlen = SBYTES (filename) - 2;
- strncpy (fn, SSDATA (filename) + 2, fnlen);
- fn[fnlen] = '\0';
- }
- else
- {
- fnlen = SBYTES (filename);
- strncpy (fn, SSDATA (filename), fnlen);
- fn[fnlen] = '\0';
- }
-
- if (lsuffix != 0) /* Bug happens on CCI if lsuffix is 0. */
- {
- strncat (fn, SSDATA (XCAR (tail)), lsuffix);
- fnlen += lsuffix;
- }
+ int prefixlen = ((SCHARS (filename) > 2
+ && SREF (filename, 0) == '/'
+ && SREF (filename, 1) == ':')
+ ? 2 : 0);
+ fnlen = SBYTES (filename) - prefixlen;
+ memcpy (fn, SDATA (filename) + prefixlen, fnlen);
+ memcpy (fn + fnlen, SDATA (XCAR (tail)), lsuffix + 1);
+ fnlen += lsuffix;
/* Check that the file exists and is not a directory. */
/* We used to only check for handlers on non-absolute file names:
if (absolute)
break;
else
continue;
- if (strncmp (previous_strings[i], SDATA (string), 10))
+ if (memcmp (previous_strings[i], SDATA (string),
+ min (10, SBYTES (string) + 1)))
break;
}
break;
if (n < 100)
- strncpy (previous_strings[i/4], SDATA (string), 10);
+ memcpy (previous_strings[i/4], min (10, SBYTES (string) + 1),
+ SDATA (string));
wv = xmalloc_widget_value ();
wv->name = SSDATA (string);
#include <unistd.h>
#include <setjmp.h>
#include <c-strcase.h>
+#include <ftoastr.h>
#include "lisp.h"
#include "blockinput.h"
[scanner scanFloat: &b];
}
else if (!strncmp(name, "rgb:", 4)) /* A newer X11 format -- rgb:r/g/b */
- {
- strncpy (hex, name + 4, 19);
- hex[19] = '\0';
- scaling = (strlen(hex) - 2) / 3;
- }
+ scaling = (snprintf (hex, sizeof hex, "%s", name + 4) - 2) / 3;
else if (name[0] == '#') /* An old X11 format; convert to newer */
{
int len = (strlen(name) - 1);
int start = (len % 3 == 0) ? 1 : len / 4 + 1;
int i;
scaling = strlen(name+start) / 3;
- for (i=0; i<3; i++) {
- strncpy(hex + i * (scaling + 1), name + start + i * scaling, scaling);
- hex[(i+1) * (scaling + 1) - 1] = '/';
- }
+ for (i = 0; i < 3; i++)
+ snprintf (hex + i * (scaling + 1), "%.*s/", scaling,
+ name + start + i * scaling);
hex[3 * (scaling + 1) - 1] = '\0';
}
ns_display_name_list);
dpyinfo->name_list_element = XCAR (ns_display_name_list);
- /* Set the name of the terminal. */
- terminal->name = xmalloc (SBYTES (display_name) + 1);
- strncpy (terminal->name, SDATA (display_name), SBYTES (display_name));
- terminal->name[SBYTES (display_name)] = 0;
+ terminal->name = xstrdup (SSDATA (display_name));
UNBLOCK_INPUT;
}
{
- char c[128];
#ifdef NS_IMPL_GNUSTEP
- strncpy (c, gnustep_base_version, sizeof (c));
+ Vwindow_system_version = build_string (gnustep_base_version);
#else
/*PSnextrelease (128, c); */
- snprintf (c, sizeof (c), "%g", NSAppKitVersionNumber);
+ char c[DBL_BUFSIZE_BOUND];
+ int len = dtoastr (c, sizeof c, 0, 0, NSAppKitVersionNumber);
+ Vwindow_system_version = make_unibyte_string (c, len);
#endif
- Vwindow_system_version = build_string (c);
}
delete_keyboard_wait_descriptor (0);
CHECK_STRING (service);
memset (&address_un, 0, sizeof address_un);
address_un.sun_family = AF_LOCAL;
- strncpy (address_un.sun_path, SSDATA (service), sizeof address_un.sun_path);
+ if (sizeof address_un.sun_path <= SBYTES (service))
+ error ("Service name too long");
+ strcpy (address_un.sun_path, SSDATA (service));
ai.ai_addr = (struct sockaddr *) &address_un;
ai.ai_addrlen = sizeof address_un;
goto open_socket;
CHECK_STRING (ifname);
- memset (rq.ifr_name, 0, sizeof rq.ifr_name);
- strncpy (rq.ifr_name, SSDATA (ifname), sizeof (rq.ifr_name));
+ if (sizeof rq.ifr_name <= SBYTES (ifname))
+ error ("interface name too long");
+ strcpy (rq.ifr_name, SSDATA (ifname));
s = socket (AF_INET, SOCK_STREAM, 0);
if (s < 0)
{
if (msg_size > errbuf_size)
{
- strncpy (errbuf, msg, errbuf_size - 1);
+ memcpy (errbuf, msg, errbuf_size - 1);
errbuf[errbuf_size - 1] = 0;
}
else
close (fd); \
return -1; \
} \
- strncpy (pty_name, ptyname, sizeof (pty_name)); \
- pty_name[sizeof (pty_name) - 1] = 0; \
+ snprintf (pty_name, sizeof pty_name, "%s", ptyname); \
sigunblock (sigmask (SIGCHLD)); \
}
{ emacs_close (fd); return -1; } \
if (!(ptyname = ptsname (fd))) \
{ emacs_close (fd); return -1; } \
- strncpy (pty_name, ptyname, sizeof (pty_name)); \
- pty_name[sizeof (pty_name) - 1] = 0; \
+ snprintf (pty_name, sizeof pty_name, "%s", ptyname); \
}
#define GC_SETJMP_WORKS 1
fatal("could not unlock slave pty"); \
if (!(ptyname = ptsname(fd))) \
fatal ("could not enable slave pty"); \
- strncpy(pty_name, ptyname, sizeof(pty_name)); \
- pty_name[sizeof(pty_name) - 1] = 0; \
+ snprintf (pty_name, sizeof pty_name, "%s", ptyname); \
}
/* Conservative garbage collection has not been tested, so for now
char procbuf[1025], *p, *q;
int fd;
ssize_t nread;
- const char *cmd = NULL;
+ static char const default_cmd[] = "???";
+ const char *cmd = default_cmd;
+ int cmdsize = sizeof default_cmd - 1;
char *cmdline = NULL;
- ptrdiff_t cmdsize = 0, cmdline_size;
+ ptrdiff_t cmdline_size;
unsigned char c;
printmax_t proc_id;
int ppid, pgrp, sess, tty, tpgid, thcount;
}
else
q = NULL;
- if (cmd == NULL)
- {
- cmd = "???";
- cmdsize = 3;
- }
/* Command name is encoded in locale-coding-system; decode it. */
cmd_str = make_unibyte_string (cmd, cmdsize);
decoded_cmd = code_convert_string_norecord (cmd_str,
}
if (!cmdline_size)
{
- if (!cmd)
- cmd = "???";
- if (!cmdsize)
- cmdsize = strlen (cmd);
cmdline_size = cmdsize + 2;
cmdline = xmalloc (cmdline_size + 1);
- strcpy (cmdline, "[");
- strcat (strncat (cmdline, cmd, cmdsize), "]");
+ sprintf (cmdline, "[%.*s]", cmdsize, cmd);
}
emacs_close (fd);
/* Command line is encoded in locale-coding-system; decode it. */
{
/* the tricky things with the sign is to make sure that
-0 is printed -0. */
- int len;
- char *tem;
sprintf (shell_position, "=%c%d%c%d",
flags & XNegative ? '-' : '+', x < 0 ? -x : x,
flags & YNegative ? '-' : '+', y < 0 ? -y : y);
- len = strlen (shell_position) + 1;
- tem = xmalloc (len);
- strncpy (tem, shell_position, len);
- XtVaSetValues (wmshell, XtNgeometry, tem, NULL);
+ XtVaSetValues (wmshell, XtNgeometry, xstrdup (shell_position), NULL);
}
else if (flags & (WidthValue | HeightValue))
{
- int len;
- char *tem;
sprintf (shell_position, "=%dx%d", pixel_width, pixel_height);
- len = strlen (shell_position) + 1;
- tem = xmalloc (len);
- strncpy (tem, shell_position, len);
- XtVaSetValues (wmshell, XtNgeometry, tem, NULL);
+ XtVaSetValues (wmshell, XtNgeometry, xstrdup (shell_position), NULL);
}
/* If the geometry spec we're using has W/H components, mark the size
static void
debug_method_add (struct window *w, char const *fmt, ...)
{
- char buffer[512];
char *method = w->desired_matrix->method;
int len = strlen (method);
int size = sizeof w->desired_matrix->method;
int remaining = size - len - 1;
va_list ap;
- va_start (ap, fmt);
- vsprintf (buffer, fmt, ap);
- va_end (ap);
if (len && remaining)
{
method[len] = '|';
--remaining, ++len;
}
- strncpy (method + len, buffer, remaining);
+ va_start (ap, fmt);
+ vsnprintf (method + len, remaining + 1, fmt, ap);
+ va_end (ap);
if (trace_redisplay_p)
fprintf (stderr, "%p (%s): %s\n",
&& STRINGP (BVAR (XBUFFER (w->buffer), name)))
? SSDATA (BVAR (XBUFFER (w->buffer), name))
: "no buffer"),
- buffer);
+ method + len);
}
#endif /* GLYPH_DEBUG */