зеркало из https://github.com/AvaloniaUI/angle.git
Converts from sprintf() to snprintf().
sprintf() is deprecated in Xcode 14, so update to safer equivalents in order to keep the compiler happy on iOS and macOS. Bug: chromium:1331345 Change-Id: Id5348088bf69cbd360d9251e6323596cb710666d Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3690747 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org>
This commit is contained in:
Родитель
ce3c0fe901
Коммит
4b911686c6
|
@ -34,7 +34,7 @@ void LoadBinaryData(const char *fileName)
|
|||
}
|
||||
char pathBuffer[1000] = {};
|
||||
|
||||
sprintf(pathBuffer, "%s/%s", gBinaryDataDir.c_str(), fileName);
|
||||
snprintf(pathBuffer, sizeof(pathBuffer), "%s/%s", gBinaryDataDir.c_str(), fileName);
|
||||
FILE *fp = fopen(pathBuffer, "rb");
|
||||
if (fp == 0)
|
||||
{
|
||||
|
|
|
@ -33,11 +33,11 @@ class GLSLTest : public ANGLETest
|
|||
|
||||
if (vectorSize == 1)
|
||||
{
|
||||
sprintf(varyingType, "float");
|
||||
snprintf(varyingType, sizeof(varyingType), "float");
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(varyingType, "vec%d", vectorSize);
|
||||
snprintf(varyingType, sizeof(varyingType), "vec%d", vectorSize);
|
||||
}
|
||||
|
||||
return std::string(varyingType);
|
||||
|
@ -49,12 +49,13 @@ class GLSLTest : public ANGLETest
|
|||
|
||||
if (arraySize == 1)
|
||||
{
|
||||
sprintf(buff, "varying %s v%d;\n", GenerateVaryingType(vectorSize).c_str(), id);
|
||||
snprintf(buff, sizeof(buff), "varying %s v%d;\n",
|
||||
GenerateVaryingType(vectorSize).c_str(), id);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(buff, "varying %s v%d[%d];\n", GenerateVaryingType(vectorSize).c_str(), id,
|
||||
arraySize);
|
||||
snprintf(buff, sizeof(buff), "varying %s v%d[%d];\n",
|
||||
GenerateVaryingType(vectorSize).c_str(), id, arraySize);
|
||||
}
|
||||
|
||||
return std::string(buff);
|
||||
|
@ -67,15 +68,16 @@ class GLSLTest : public ANGLETest
|
|||
|
||||
if (arraySize == 1)
|
||||
{
|
||||
sprintf(buff, "\t v%d = %s(1.0);\n", id, GenerateVaryingType(vectorSize).c_str());
|
||||
snprintf(buff, sizeof(buff), "\t v%d = %s(1.0);\n", id,
|
||||
GenerateVaryingType(vectorSize).c_str());
|
||||
returnString += buff;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < arraySize; i++)
|
||||
{
|
||||
sprintf(buff, "\t v%d[%d] = %s(1.0);\n", id, i,
|
||||
GenerateVaryingType(vectorSize).c_str());
|
||||
snprintf(buff, sizeof(buff), "\t v%d[%d] = %s(1.0);\n", id, i,
|
||||
GenerateVaryingType(vectorSize).c_str());
|
||||
returnString += buff;
|
||||
}
|
||||
}
|
||||
|
@ -88,7 +90,7 @@ class GLSLTest : public ANGLETest
|
|||
if (arraySize == 1)
|
||||
{
|
||||
char buff[100];
|
||||
sprintf(buff, "v%d + ", id);
|
||||
snprintf(buff, sizeof(buff), "v%d + ", id);
|
||||
return std::string(buff);
|
||||
}
|
||||
else
|
||||
|
@ -97,7 +99,7 @@ class GLSLTest : public ANGLETest
|
|||
for (int i = 0; i < arraySize; i++)
|
||||
{
|
||||
char buff[100];
|
||||
sprintf(buff, "v%d[%d] + ", id, i);
|
||||
snprintf(buff, sizeof(buff), "v%d[%d] + ", id, i);
|
||||
returnString += buff;
|
||||
}
|
||||
return returnString;
|
||||
|
|
|
@ -349,7 +349,7 @@ void WriteResultsFile(bool interrupted,
|
|||
jsResult.AddMember("times", times, allocator);
|
||||
|
||||
char testName[500];
|
||||
id.sprintfName(testName);
|
||||
id.snprintfName(testName, sizeof(testName));
|
||||
js::Value jsName;
|
||||
jsName.SetString(testName, allocator);
|
||||
|
||||
|
@ -1008,9 +1008,9 @@ TestIdentifier::~TestIdentifier() = default;
|
|||
|
||||
TestIdentifier &TestIdentifier::operator=(const TestIdentifier &other) = default;
|
||||
|
||||
void TestIdentifier::sprintfName(char *outBuffer) const
|
||||
void TestIdentifier::snprintfName(char *outBuffer, size_t maxLen) const
|
||||
{
|
||||
sprintf(outBuffer, "%s.%s", testSuiteName.c_str(), testName.c_str());
|
||||
snprintf(outBuffer, maxLen, "%s.%s", testSuiteName.c_str(), testName.c_str());
|
||||
}
|
||||
|
||||
// static
|
||||
|
|
|
@ -34,7 +34,7 @@ struct TestIdentifier
|
|||
static bool ParseFromString(const std::string &str, TestIdentifier *idOut);
|
||||
|
||||
bool valid() const { return !testName.empty(); }
|
||||
void sprintfName(char *outBuffer) const;
|
||||
void snprintfName(char *outBuffer, size_t maxLen) const;
|
||||
|
||||
std::string testSuiteName;
|
||||
std::string testName;
|
||||
|
|
|
@ -98,8 +98,7 @@ ReadResult ReadFromFile(int fd, std::string *out)
|
|||
void ReadEntireFile(int fd, std::string *out)
|
||||
{
|
||||
while (ReadFromFile(fd, out) == ReadResult::GotData)
|
||||
{
|
||||
}
|
||||
{}
|
||||
}
|
||||
|
||||
class PosixProcess : public Process
|
||||
|
@ -340,8 +339,8 @@ void Sleep(unsigned int milliseconds)
|
|||
{
|
||||
long milliseconds_long = milliseconds;
|
||||
timespec sleepTime = {
|
||||
.tv_sec = milliseconds_long / 1000,
|
||||
.tv_nsec = (milliseconds_long % 1000) * 1000000,
|
||||
.tv_sec = milliseconds_long / 1000,
|
||||
.tv_nsec = (milliseconds_long % 1000) * 1000000,
|
||||
};
|
||||
|
||||
nanosleep(&sleepTime, nullptr);
|
||||
|
@ -420,7 +419,7 @@ bool GetTempDir(char *tempDirOut, uint32_t maxDirNameLen)
|
|||
bool CreateTemporaryFileInDir(const char *dir, char *tempFileNameOut, uint32_t maxFileNameLen)
|
||||
{
|
||||
std::string tempFile = TempFileName();
|
||||
sprintf(tempFileNameOut, "%s/%s", dir, tempFile.c_str());
|
||||
snprintf(tempFileNameOut, maxFileNameLen, "%s/%s", dir, tempFile.c_str());
|
||||
int fd = mkstemp(tempFileNameOut);
|
||||
close(fd);
|
||||
return fd != -1;
|
||||
|
|
Загрузка…
Ссылка в новой задаче