[PATCH:libxtrans 10/10] Convert a bunch of sprintf calls to snprintf
Alan Coopersmith
alan.coopersmith at oracle.com
Tue Sep 27 14:28:30 PDT 2011
Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
Xtranslcl.c | 32 +++++++++++++++++++-------------
Xtranssock.c | 6 +++---
2 files changed, 22 insertions(+), 16 deletions(-)
diff --git a/Xtranslcl.c b/Xtranslcl.c
index e5b3833..8466ddc 100644
--- a/Xtranslcl.c
+++ b/Xtranslcl.c
@@ -322,12 +322,14 @@ TRANS(PTSOpenClient)(XtransConnInfo ciptr, char *port)
#else
if (port && *port ) {
if( *port == '/' ) { /* A full pathname */
- (void) sprintf(server_path, "%s", port);
- } else {
- (void) sprintf(server_path, "%s%s", PTSNODENAME, port);
- }
+ snprintf(server_path, sizeof(server_path), "%s", port);
+ } else {
+ snprintf(server_path, sizeof(server_path), "%s%s",
+ PTSNODENAME, port);
+ }
} else {
- (void) sprintf(server_path, "%s%d", PTSNODENAME, getpid());
+ snprintf(server_path, sizeof(server_path), "%s%d",
+ PTSNODENAME, getpid());
}
@@ -1275,12 +1277,14 @@ TRANS(PTSReopenServer)(XtransConnInfo ciptr, int fd, char *port)
#else
if (port && *port ) {
if( *port == '/' ) { /* A full pathname */
- (void) sprintf(server_path, "%s", port);
- } else {
- (void) sprintf(server_path, "%s%s", PTSNODENAME, port);
- }
+ snprintf(server_path, sizeof(server_path), "%s", port);
+ } else {
+ snprintf(server_path, sizeof(server_path), "%s%s",
+ PTSNODENAME, port);
+ }
} else {
- (void) sprintf(server_path, "%s%ld", PTSNODENAME, (long)getpid());
+ snprintf(server_path, sizeof(server_path), "%s%ld",
+ PTSNODENAME, (long)getpid());
}
if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0)
@@ -1314,12 +1318,14 @@ TRANS(NAMEDReopenServer)(XtransConnInfo ciptr, int fd _X_UNUSED, char *port)
#else
if ( port && *port ) {
if( *port == '/' ) { /* A full pathname */
- (void) sprintf(server_path, "%s", port);
+ snprintf(server_path, sizeof(server_path),"%s", port);
} else {
- (void) sprintf(server_path, "%s%s", NAMEDNODENAME, port);
+ snprintf(server_path, sizeof(server_path), "%s%s",
+ NAMEDNODENAME, port);
}
} else {
- (void) sprintf(server_path, "%s%ld", NAMEDNODENAME, (long)getpid());
+ snprintf(server_path, sizeof(server_path), "%s%ld",
+ NAMEDNODENAME, (long)getpid());
}
if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0)
diff --git a/Xtranssock.c b/Xtranssock.c
index 1275196..955516d 100644
--- a/Xtranssock.c
+++ b/Xtranssock.c
@@ -840,7 +840,7 @@ set_sun_path(const char *port, const char *upath, char *path, int abstract)
if (strlen(port) + strlen(upath) > maxlen)
return -1;
- sprintf(path, "%s%s%s", at, upath, port);
+ snprintf(path, sizeof(s.sun_path), "%s%s%s", at, upath, port);
return 0;
}
#endif
@@ -960,7 +960,7 @@ TRANS(SocketINETCreateListener) (XtransConnInfo ciptr, char *port, unsigned int
{
/* fixup the server port address */
tmpport = X_TCP_PORT + strtol (port, (char**)NULL, 10);
- sprintf (portbuf,"%lu", tmpport);
+ snprintf (portbuf, sizeof(portbuf), "%lu", tmpport);
port = portbuf;
}
#endif
@@ -1457,7 +1457,7 @@ TRANS(SocketINETConnect) (XtransConnInfo ciptr, char *host, char *port)
if (is_numeric (port))
{
long tmpport = X_TCP_PORT + strtol (port, (char**)NULL, 10);
- sprintf (portbuf, "%lu", tmpport);
+ snprintf (portbuf, sizeof(portbuf), "%lu", tmpport);
port = portbuf;
}
#endif
--
1.7.3.2
More information about the xorg-devel
mailing list