Skip to content

Commit d2469f4

Browse files
committed
Use snprintf() instead of sprintf()
1 parent fa3e494 commit d2469f4

File tree

6 files changed

+18
-19
lines changed

6 files changed

+18
-19
lines changed

client/ClientWin.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright (C)2004 Landmark Graphics Corporation
22
// Copyright (C)2005, 2006 Sun Microsystems, Inc.
3-
// Copyright (C)2009, 2011, 2014, 2019, 2021 D. R. Commander
3+
// Copyright (C)2009, 2011, 2014, 2019, 2021, 2025 D. R. Commander
44
//
55
// This library is free software and may be redistributed and/or modified under
66
// the terms of the wxWindows Library License, Version 3.1 or (at your option)
@@ -71,7 +71,7 @@ void ClientWin::initGL(void)
7171
{
7272
GLFrame *newfb = NULL;
7373
char dpystr[80];
74-
sprintf(dpystr, ":%d.0", dpynum);
74+
snprintf(dpystr, 80, ":%d.0", dpynum);
7575
CriticalSection::SafeLock l(mutex);
7676

7777
if(drawMethod == RR_DRAWOGL)
@@ -107,7 +107,7 @@ void ClientWin::initX11(void)
107107
{
108108
FBXFrame *newfb = NULL;
109109
char dpystr[80];
110-
sprintf(dpystr, ":%d.0", dpynum);
110+
snprintf(dpystr, 80, ":%d.0", dpynum);
111111
CriticalSection::SafeLock l(mutex);
112112

113113
if(drawMethod == RR_DRAWX11)
@@ -153,7 +153,7 @@ Frame *ClientWin::getFrame(bool useXV)
153153
if(!xvframes[cfindex])
154154
{
155155
char dpystr[80];
156-
sprintf(dpystr, ":%d.0", dpynum);
156+
snprintf(dpystr, 80, ":%d.0", dpynum);
157157
xvframes[cfindex] = new XVFrame(dpystr, window);
158158
if(!xvframes[cfindex]) THROW("Could not allocate class instance");
159159
}

client/vglclient.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright (C)2004 Landmark Graphics Corporation
22
// Copyright (C)2005, 2006 Sun Microsystems, Inc.
3-
// Copyright (C)2011-2012, 2014, 2017-2019, 2021 D. R. Commander
3+
// Copyright (C)2011-2012, 2014, 2017-2019, 2021, 2025 D. R. Commander
44
//
55
// This library is free software and may be redistributed and/or modified under
66
// the terms of the wxWindows Library License, Version 3.1 or (at your option)
@@ -145,9 +145,9 @@ void killproc(bool userOnly)
145145

146146
if(pid == getpid()) continue;
147147
#ifdef sun
148-
sprintf(temps, "/proc/%s/psinfo", dent->d_name);
148+
snprintf(temps, 1024, "/proc/%s/psinfo", dent->d_name);
149149
#else
150-
sprintf(temps, "/proc/%s/stat", dent->d_name);
150+
snprintf(temps, 1024, "/proc/%s/stat", dent->d_name);
151151
#endif
152152
if((fd = open(temps, O_RDONLY)) == -1) continue;
153153
if(fstat(fd, &fsbuf) != -1 && (fsbuf.st_uid == getuid() || !userOnly))

common/Profiler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright (C)2004 Landmark Graphics Corporation
22
// Copyright (C)2005, 2006 Sun Microsystems, Inc.
3-
// Copyright (C)2014, 2021 D. R. Commander
3+
// Copyright (C)2014, 2021, 2025 D. R. Commander
44
//
55
// This library is free software and may be redistributed and/or modified under
66
// the terms of the wxWindows Library License, Version 3.1 or (at your option)
@@ -15,8 +15,8 @@
1515
#include "Profiler.h"
1616
#include <stdlib.h>
1717
#include <string.h>
18+
#include "vglutil.h"
1819
#ifdef _MSC_VER
19-
#define snprintf _snprintf
2020
#define strdup _strdup
2121
#endif
2222
#include "Timer.h"

demos/glinfo_common.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Copyright (C) 1999-2014 Brian Paul All Rights Reserved.
33
* Copyright (C) 2005 Sun Microsystems, Inc. All Rights Reserved.
4-
* Copyright (C) 2014, 2018-2019 D. R. Commander All Rights Reserved.
4+
* Copyright (C) 2014, 2018-2019, 2025 D. R. Commander All Rights Reserved.
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a
77
* copy of this software and associated documentation files (the "Software"),
@@ -28,9 +28,7 @@
2828
#include <string.h>
2929
#include "glinfo_common.h"
3030

31-
#ifdef _WIN32
32-
#define snprintf _snprintf
33-
#endif
31+
#include "vglutil.h"
3432

3533
#ifndef GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT
3634
#define GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT 0x00000001

include/Error.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright (C)2004 Landmark Graphics Corporation
22
// Copyright (C)2005 Sun Microsystems, Inc.
3-
// Copyright (C)2014, 2019-2021 D. R. Commander
3+
// Copyright (C)2014, 2019-2021, 2025 D. R. Commander
44
//
55
// This library is free software and may be redistributed and/or modified under
66
// the terms of the wxWindows Library License, Version 3.1 or (at your option)
@@ -24,6 +24,7 @@
2424
#include <errno.h>
2525
#include <exception>
2626
#include <typeinfo>
27+
#include "vglutil.h"
2728

2829

2930
#define GET_METHOD(e) \
@@ -60,7 +61,7 @@ namespace util
6061
void init(const char *method_, char *message_, int line)
6162
{
6263
message[0] = 0;
63-
if(line >= 1) sprintf(message, "%d: ", line);
64+
if(line >= 1) snprintf(message, MLEN + 1, "%d: ", line);
6465
if(!method_) method_ = "(Unknown error location)";
6566
method = method_;
6667
if(message_)

server/vglconfigLauncher.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright (C)2007 Sun Microsystems, Inc.
2-
// Copyright (C)2014, 2018-2021 D. R. Commander
2+
// Copyright (C)2014, 2018-2021, 2025 D. R. Commander
33
//
44
// This library is free software and may be redistributed and/or modified under
55
// the terms of the wxWindows Library License, Version 3.1 or (at your option)
@@ -56,7 +56,7 @@ namespace faker
5656
unsetenv("LD_PRELOAD");
5757
unsetenv("LD_PRELOAD_32");
5858
unsetenv("LD_PRELOAD_64");
59-
sprintf(commandLine, "%s -display %s -shmid %d -ppid %d",
59+
snprintf(commandLine, 1024, "%s -display %s -shmid %d -ppid %d",
6060
fconfig.config, DisplayString(dpy), shmid, getpid());
6161
if(system(commandLine) == -1) THROW_UNIX();
6262
}
@@ -89,9 +89,9 @@ namespace faker
8989
{
9090
errno = ENOMEM; return -1;
9191
}
92-
sprintf(str, "%s=", name);
92+
snprintf(str, strlen(name) + 2, "%s=", name);
9393
putenv(str);
94-
strcpy(str, "=");
94+
strncpy(str, "=", strlen(name) + 2);
9595
putenv(str);
9696
return 0;
9797
}

0 commit comments

Comments
 (0)