Skip to content

Commit

Permalink
Fixed: Various cases of undefined behavior
Browse files Browse the repository at this point in the history
Notably, taskBarBlur must be available before other widgets.
  • Loading branch information
skyjake committed Oct 29, 2018
1 parent 62ccd35 commit c7ab163
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 16 deletions.
7 changes: 5 additions & 2 deletions doomsday/apps/client/src/ui/clientwindow.cpp
Expand Up @@ -179,6 +179,10 @@ DENG2_PIMPL(ClientWindow)
{
Style &style = ClientApp::windowSystem().style();

// This is a shared widget so it may be accessed during initialization of other widgets;
// create it first.
taskBarBlur = new LabelWidget("taskbar-blur");

gameWidth ->set(root.viewWidth());
gameHeight->set(root.viewHeight());

Expand Down Expand Up @@ -293,10 +297,8 @@ DENG2_PIMPL(ClientWindow)
fsBusy->useMiniStyle();
fsBusy->setText("Files");
fsBusy->setTextAlignment(ui::AlignRight);
FS::get().audienceForBusy() += this;

// Everything behind the task bar can be blurred with this widget.
taskBarBlur = new LabelWidget("taskbar-blur");
if (style.isBlurringAllowed())
{
taskBarBlur->set(GuiWidget::Background(Vector4f(1, 1, 1, 1), GuiWidget::Background::Blurred));
Expand Down Expand Up @@ -393,6 +395,7 @@ DENG2_PIMPL(ClientWindow)
taskBar->close();
}

FS::get().audienceForBusy() += this;
Loop::get().timer(1.0, [this] () { showOrHideQuitButton(); });
}

Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/libdoomsday/include/doomsday/filesys/file.h
Expand Up @@ -76,7 +76,7 @@ class LIBDOOMSDAY_PUBLIC File1
* @param _info Info descriptor for the file. A copy is made.
* @param container Container of this file. Can be @c NULL.
*/
File1(FileHandle &hndl, String _path, FileInfo const &_info, File1 *container = 0);
File1(FileHandle *hndl, String _path, FileInfo const &_info, File1 *container = 0);

/**
* Release all memory acquired for objects linked with this resource.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/libdoomsday/include/doomsday/filesys/wad.h
Expand Up @@ -57,7 +57,7 @@ class LIBDOOMSDAY_PUBLIC Wad : public File1, public LumpIndex
class LumpFile : public File1
{
public:
LumpFile(Entry &entry, FileHandle &hndl, String path, FileInfo const &info,
LumpFile(Entry &entry, FileHandle *hndl, String path, FileInfo const &info,
File1 *container);

/// @return Name of this file.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/libdoomsday/include/doomsday/filesys/zip.h
Expand Up @@ -59,7 +59,7 @@ class LIBDOOMSDAY_PUBLIC Zip : public File1, public LumpIndex
class LumpFile : public File1
{
public:
LumpFile(Entry &entry, FileHandle &hndl, String path, FileInfo const &info,
LumpFile(Entry &entry, FileHandle *hndl, String path, FileInfo const &info,
File1 *container);

/// @return Name of this file.
Expand Down
4 changes: 2 additions & 2 deletions doomsday/apps/libdoomsday/src/filesys/file.cpp
Expand Up @@ -28,8 +28,8 @@

namespace de {

File1::File1(FileHandle &hndl, String _path, FileInfo const &_info, File1 *_container)
: handle_(&hndl)
File1::File1(FileHandle *hndl, String _path, FileInfo const &_info, File1 *_container)
: handle_(hndl)
, info_(_info)
, container_(_container)
, flags(DefaultFlags)
Expand Down
7 changes: 3 additions & 4 deletions doomsday/apps/libdoomsday/src/filesys/wad.cpp
Expand Up @@ -126,7 +126,7 @@ static QString Wad_invalidIndexMessage(int invalidIdx, int lastValidIdx)

using namespace internal;

Wad::LumpFile::LumpFile(Entry &entry, FileHandle &hndl, String path,
Wad::LumpFile::LumpFile(Entry &entry, FileHandle *hndl, String path,
FileInfo const &info, File1 *container)
: File1(hndl, path, info, container)
, entry(entry)
Expand Down Expand Up @@ -182,7 +182,7 @@ DENG2_PIMPL_NOREF(Wad)
};

Wad::Wad(FileHandle &hndl, String path, FileInfo const &info, File1 *container)
: File1(hndl, path, info, container)
: File1(&hndl, path, info, container)
, LumpIndex()
, d(new Impl)
{
Expand Down Expand Up @@ -212,8 +212,7 @@ Wad::Wad(FileHandle &hndl, String path, FileInfo const &info, File1 *container)
entry.offset = lump.offset;
entry.size = lump.size;

FileHandle *dummy = 0; /// @todo Fixme!
LumpFile *lumpFile = new LumpFile(entry, *dummy, entry.path(),
LumpFile *lumpFile = new LumpFile(entry, nullptr, entry.path(),
FileInfo(lastModified(), // Inherited from the container (note recursion).
i, entry.offset, entry.size, entry.size),
this);
Expand Down
7 changes: 3 additions & 4 deletions doomsday/apps/libdoomsday/src/filesys/zip.cpp
Expand Up @@ -269,7 +269,7 @@ static bool applyGamePathMappings(String &path)

using namespace internal;

Zip::LumpFile::LumpFile(Entry &entry, FileHandle &hndl, String path,
Zip::LumpFile::LumpFile(Entry &entry, FileHandle *hndl, String path,
FileInfo const &info, File1 *container)
: File1(hndl, path, info, container)
, entry(entry)
Expand Down Expand Up @@ -361,7 +361,7 @@ DENG2_PIMPL(Zip)
};

Zip::Zip(FileHandle &hndl, String path, FileInfo const &info, File1 *container)
: File1(hndl, path, info, container)
: File1(&hndl, path, info, container)
, LumpIndex(true/*paths are unique*/)
, d(new Impl(this))
{
Expand Down Expand Up @@ -510,8 +510,7 @@ Zip::Zip(FileHandle &hndl, String path, FileInfo const &info, File1 *container)
entry.size = DD_ULONG(header->size);
entry.compressedSize = compressedSize;

FileHandle *dummy = 0; /// @todo Fixme!
LumpFile *lumpFile = new LumpFile(entry, *dummy, entry.path(),
LumpFile *lumpFile = new LumpFile(entry, nullptr, entry.path(),
FileInfo(lastModified(), // Inherited from the file (note recursion).
lumpIdx, entry.offset, entry.size, entry.compressedSize),
this);
Expand Down
4 changes: 4 additions & 0 deletions doomsday/sdk/libcore/src/core/loop.cpp
Expand Up @@ -64,6 +64,10 @@ Loop::Loop() : d(new Impl(this))

void Loop::setRate(double freqHz)
{
if (fequal(freqHz, 0.0))
{
freqHz = 120.0;
}
d->interval = 1.0 / freqHz;
d->timer->setInterval(de::max(1, int(d->interval.asMilliSeconds())));
}
Expand Down
7 changes: 6 additions & 1 deletion doomsday/sdk/libcore/src/data/value.cpp
Expand Up @@ -61,7 +61,12 @@ Value::Number Value::asSafeNumber(Number const &defaultValue) const

int Value::asInt() const
{
return round<int>(asNumber());
const double num = asNumber();
if (num > std::numeric_limits<int>::max())
{
return std::numeric_limits<int>::max();
}
return round<int>(num);
}

StringList Value::asStringList() const
Expand Down
1 change: 1 addition & 0 deletions doomsday/sdk/libgui/src/guiapp.cpp
Expand Up @@ -41,6 +41,7 @@ DENG2_PIMPL(GuiApp)

Impl(Public *i) : Base(i)
{
loop.setRate(120);
loop.audienceForIteration() += self();

// The default render thread is the main thread.
Expand Down

0 comments on commit c7ab163

Please sign in to comment.