Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

start compiling editor #826

Merged
merged 1 commit into from
Apr 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions projects/genie.lua
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,10 @@ end
function useLua()
if _OPTIONS["static-plugins"] then
linkLib("lua")
else
defines { "LUA_BUILD_AS_DLL" }
else
configuration "windows"
defines { "LUA_BUILD_AS_DLL" }
configuration {}
end
includedirs { "../external/lua/include" }
end
Expand Down
8 changes: 4 additions & 4 deletions src/editor/asset_browser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ bool AssetBrowser::resourceInput(const char* label, const char* str_id, char* bu
m_wanted_resource = buf;
}
ImGui::SameLine();
ImGui::Text(label);
ImGui::Text("%s", label);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the problem with this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gcc can check string format strings and arguments and gives warning (which becomes error with -Werror)

../../../src/editor/asset_browser.cpp: In member function ‘bool AssetBrowser::resourceInput(const char*, const char*, char*, int, Lumix::uint32)’:
../../../src/editor/asset_browser.cpp:305:19: error: format not a string literal and no format arguments [-Werror=format-security]
  ImGui::Text(label);
                   ^
cc1plus: all warnings being treated as errors

If you pass printf-like function not a string literal but some received string, this function can misinterpret it (suppose this string has %s in it) and read arbitrary memory.

ImGui::PopItemWidth();

if (ImGui::BeginResizablePopup(popup_name, ImVec2(300, 300)))
Expand Down Expand Up @@ -363,7 +363,7 @@ void AssetBrowser::onGUIResource()

const char* path = m_selected_resource->getPath().c_str();
ImGui::Separator();
ImGui::LabelText("Selected resource", path);
ImGui::LabelText("Selected resource", "%s", path);
if (!m_history.empty() && ImGui::Button("Back"))
{
selectResource(m_history.back());
Expand All @@ -383,7 +383,7 @@ void AssetBrowser::onGUIResource()
if (m_metadata.getString(
m_selected_resource->getPath().getHash(), SOURCE_HASH, source, Lumix::lengthOf(source)))
{
ImGui::LabelText("Source", source);
ImGui::LabelText("Source", "%s", source);
}

auto resource_type = getResourceType(path);
Expand Down Expand Up @@ -475,4 +475,4 @@ void AssetBrowser::findResources()
processDir(base_path, Lumix::stringLength(base_path));
auto* patch_device = m_editor.getEngine().getPatchFileDevice();
if (patch_device) processDir(patch_device->getBasePath(), Lumix::stringLength(patch_device->getBasePath()));
}
}
3 changes: 2 additions & 1 deletion src/editor/editor_icon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ struct EditorIconsImpl : public EditorIcons
{
for (int i = 0; i < lengthOf(ICONS); ++i)
{
m_models[i] = m_render_interface->loadModel(Path(ICONS[i]));
Path path(ICONS[i]);
m_models[i] = m_render_interface->loadModel(path);
}
}
}
Expand Down
15 changes: 12 additions & 3 deletions src/editor/imgui/imconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,25 @@
#pragma once

//---- Define assertion handler. Defaults to calling assert().
#define IM_ASSERT(_EXPR) do { if(!(_EXPR)) __debugbreak(); } while(false)
#ifdef _WIN32
#define IM_ASSERT(_EXPR) do { if(!(_EXPR)) __debugbreak(); } while(false)
#endif

//---- Define attributes of all API symbols declarations, e.g. for DLL under Windows.
#ifdef STATIC_PLUGINS
#define IMGUI_API
#else
#ifdef _WIN32
#define IMGUI_LIBRARY_EXPORT __declspec(dllexport)
#define IMGUI_LIBRARY_IMPORT __declspec(dllimport)
#else
#define IMGUI_LIBRARY_EXPORT __attribute__((visibility("default")))
#define IMGUI_LIBRARY_IMPORT
#endif
#ifdef BUILDING_EDITOR
#define IMGUI_API __declspec( dllexport )
#define IMGUI_API IMGUI_LIBRARY_EXPORT
#else
#define IMGUI_API __declspec( dllimport )
#define IMGUI_API IMGUI_LIBRARY_IMPORT
#endif
#endif

Expand Down
16 changes: 8 additions & 8 deletions src/editor/import_asset_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2064,7 +2064,7 @@ void ImportAssetDialog::onMaterialsGUI()
{
aiString material_name;
mat.material->Get(AI_MATKEY_NAME, material_name);
if (ImGui::TreeNode(mat.material, material_name.C_Str()))
if (ImGui::TreeNode(mat.material, "%s", material_name.C_Str()))
{
ImGui::Checkbox("Import material", &mat.import);
ImGui::Checkbox("Alpha cutout material", &mat.alpha_cutout);
Expand All @@ -2081,7 +2081,7 @@ void ImportAssetDialog::onMaterialsGUI()
ImGui::Separator();
for (int i = 0; i < mat.texture_count; ++i)
{
ImGui::Text(mat.textures[i].path);
ImGui::Text("%s", mat.textures[i].path);
ImGui::NextColumn();
ImGui::Checkbox(Lumix::StaticString<20>("###imp", i), &mat.textures[i].import);
ImGui::NextColumn();
Expand All @@ -2096,7 +2096,7 @@ void ImportAssetDialog::onMaterialsGUI()
}
}
ImGui::SameLine();
ImGui::Text(mat.textures[i].src);
ImGui::Text("%s", mat.textures[i].src);
}
ImGui::Columns();

Expand Down Expand Up @@ -2151,13 +2151,13 @@ void ImportAssetDialog::onMeshesGUI()
{
const char* name = mesh.mesh->mName.C_Str();
if (name[0] == 0) name = getMeshName(mesh.scene, mesh.mesh).C_Str();
ImGui::Text(name);
ImGui::Text("%s", name);
ImGui::NextColumn();

auto* material = mesh.scene->mMaterials[mesh.mesh->mMaterialIndex];
aiString material_name;
material->Get(AI_MATKEY_NAME, material_name);
ImGui::Text(material_name.C_Str());
ImGui::Text("%s", material_name.C_Str());
ImGui::NextColumn();

ImGui::Checkbox(Lumix::StaticString<30>("###mesh", (Lumix::uint64)&mesh), &mesh.import);
Expand Down Expand Up @@ -2479,7 +2479,7 @@ void ImportAssetDialog::onGUI()
{
char msg[1024];
getMessage(msg, sizeof(msg));
ImGui::Text(msg);
ImGui::Text("%s", msg);
if (ImGui::Button("OK"))
{
setMessage("");
Expand All @@ -2506,7 +2506,7 @@ void ImportAssetDialog::onGUI()

{
Lumix::MT::SpinLock lock(m_mutex);
ImGui::Text(m_import_message);
ImGui::Text("%s", m_import_message);
if (m_progress_fraction >= 0) ImGui::ProgressBar(m_progress_fraction);
}
ImGui::EndDock();
Expand Down Expand Up @@ -2623,4 +2623,4 @@ void ImportAssetDialog::onGUI()
}
}
ImGui::EndDock();
}
}
4 changes: 2 additions & 2 deletions src/editor/log_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void LogUI::showNotifications()
for (int i = 0; i < m_notifications.size(); ++i)
{
if (i > 0) ImGui::Separator();
ImGui::Text(m_notifications[i].message.c_str());
ImGui::Text("%s", m_notifications[i].message.c_str());
}
ImGui::End();
}
Expand Down Expand Up @@ -197,7 +197,7 @@ void LogUI::onGUI()
const char* msg = (*messages)[i].c_str();
if (filter[0] == '\0' || strstr(msg, filter) != nullptr)
{
ImGui::Text(msg);
ImGui::Text("%s", msg);
}
}
}
Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions src/editor/profiler_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ struct ProfilerUIImpl : public ProfilerUI
{
if (m_filter[0] == 0 || Lumix::stristr(log.path, m_filter) != 0)
{
ImGui::Text(log.path);
ImGui::Text("%s", log.path);
ImGui::NextColumn();
ImGui::Text("%f", log.time * 1000.0f);
ImGui::NextColumn();
Expand Down Expand Up @@ -801,12 +801,12 @@ void ProfilerUIImpl::onGUIResources()
continue;
}

ImGui::Text(iter.value()->getPath().c_str());
ImGui::Text("%s", iter.value()->getPath().c_str());
ImGui::NextColumn();
ImGui::Text("%.3fKB", iter.value()->size() / 1024.0f);
sum += iter.value()->size();
ImGui::NextColumn();
ImGui::Text(getResourceStateString(iter.value()->getState()));
ImGui::Text("%s", getResourceStateString(iter.value()->getState()));
ImGui::NextColumn();
ImGui::Text("%u", iter.value()->getRefCount());
ImGui::NextColumn();
Expand Down Expand Up @@ -916,7 +916,7 @@ void ProfilerUIImpl::showAllocationTree(AllocationStackNode* node, int column)
Lumix::copyString(fn_name, "N/A");
}

if (ImGui::TreeNode(node, fn_name))
if (ImGui::TreeNode(node, "%s", fn_name))
{
node->m_opened = true;
for (auto* child : node->m_children)
Expand Down Expand Up @@ -995,7 +995,7 @@ static void showThreadColumn(ProfilerUIImpl& profiler, Column column)
}
else
{
if (ImGui::TreeNode(root, thread_name))
if (ImGui::TreeNode(root, "%s", thread_name))
{
profiler.m_threads[i].opened = true;
profiler.showProfileBlock(root, column);
Expand Down
4 changes: 2 additions & 2 deletions src/editor/property_grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ bool PropertyGrid::entityInput(const char* label, const char* str_id, Lumix::Ent
item_w - ImGui::CalcTextSize("...").x - style.FramePadding.x * 2 - style.ItemSpacing.x);
char buf[50];
getEntityListDisplayName(m_editor, buf, sizeof(buf), entity);
ImGui::LabelText("", buf);
ImGui::LabelText("", "%s", buf);
ImGui::SameLine();
Lumix::StaticString<30> popup_name("pu", str_id);
if (ImGui::Button(Lumix::StaticString<30>("...###br", str_id)))
Expand All @@ -469,7 +469,7 @@ bool PropertyGrid::entityInput(const char* label, const char* str_id, Lumix::Ent
}

ImGui::SameLine();
ImGui::Text(label);
ImGui::Text("%s", label);
ImGui::PopItemWidth();

if (ImGui::BeginPopup(popup_name))
Expand Down
2 changes: 1 addition & 1 deletion src/editor/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ void Settings::showShortcutSettings(Action** actions, int actions_count)
Action& a = *actions[i];
if (m_filter[0] == 0 || Lumix::stristr(a.label, m_filter) != 0)
{
ImGui::Text(a.label);
ImGui::Text("%s", a.label);
ImGui::NextColumn();
shortcutInput(a.shortcut[0]);
ImGui::NextColumn();
Expand Down
8 changes: 4 additions & 4 deletions src/editor/stb/stb_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -594,10 +594,10 @@ typedef unsigned int stbi__uint32;
typedef signed int stbi__int32;
#else
#include <stdint.h>
typedef uint16 stbi__uint16;
typedef int16 stbi__int16;
typedef uint32 stbi__uint32;
typedef int32 stbi__int32;
typedef uint16_t stbi__uint16;
typedef int16_t stbi__int16;
typedef uint32_t stbi__uint32;
typedef int32_t stbi__int32;
#endif

// should produce compiler error if size is wrong
Expand Down
6 changes: 3 additions & 3 deletions src/editor/studio_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ class StudioAppImpl : public StudioApp
if (!PlatformInterface::isWindowActive()) stats << " - inactive window";
auto stats_size = ImGui::CalcTextSize(stats);
ImGui::SameLine(ImGui::GetContentRegionMax().x - stats_size.x);
ImGui::Text(stats);
ImGui::Text("%s", (const char*)stats);

if (m_log_ui->getUnreadErrorCount() == 1)
{
Expand All @@ -750,7 +750,7 @@ class StudioAppImpl : public StudioApp
ImGui::SameLine(ImGui::GetContentRegionMax().x - stats_size.x);
auto error_stats_size = ImGui::CalcTextSize(error_stats);
ImGui::SameLine(ImGui::GetContentRegionMax().x - stats_size.x - error_stats_size.x);
ImGui::TextColored(ImVec4(1, 0, 0, 1), error_stats);
ImGui::TextColored(ImVec4(1, 0, 0, 1), "%s", (const char*)error_stats);
}

ImGui::EndMainMenuBar();
Expand Down Expand Up @@ -1730,4 +1730,4 @@ void StudioApp::StaticPluginRegister::create(const char* name, StudioApp& app)
}
i = i->next;
}
}
}