Skip to content

Commit

Permalink
moc: Store errno after fopen call
Browse files Browse the repository at this point in the history
To avoid QFile::encodeName() potentially overriding the value.

Pick-to: 6.2 6.5 6.6
Task-number: QTBUG-101926
Change-Id: Ie751df877d6624238ded344474b5eccc324ec541
Reviewed-by: Fabian Kosmale <[email protected]>
  • Loading branch information
alcroito committed Jul 12, 2023
1 parent 258e7ed commit dd1b7b5
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/tools/moc/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,9 +549,12 @@ int runMoc(int argc, char **argv)
f = fopen(QFile::encodeName(jsonOutputFileName).constData(), "w");
if (!f)
#endif
{
const auto fopen_errno = errno;
fprintf(stderr, "moc: Cannot create JSON output file %s. %s\n",
QFile::encodeName(jsonOutputFileName).constData(),
strerror(errno));
strerror(fopen_errno));
}
jsonOutput.reset(f);
}
} else { // use stdout
Expand Down Expand Up @@ -596,9 +599,12 @@ int runMoc(int argc, char **argv)
depFileHandleRaw = fopen(QFile::encodeName(depOutputFileName).constData(), "w");
if (!depFileHandleRaw)
#endif
{
const auto fopen_errno = errno;
fprintf(stderr, "moc: Cannot create dep output file '%s'. %s\n",
QFile::encodeName(depOutputFileName).constData(),
strerror(errno));
strerror(fopen_errno));
}
depFileHandle.reset(depFileHandleRaw);

if (!depFileHandle.isNull()) {
Expand Down

0 comments on commit dd1b7b5

Please sign in to comment.