From 24ef2830d151bd89db1df70c0be4a99fd7e7e77c Mon Sep 17 00:00:00 2001
From: Svornost <11434-svornost@users.noreply.gitgud.io>
Date: Thu, 5 Mar 2020 00:26:34 -0800
Subject: [PATCH] Don't crash FCHost when console.log is called from unknown
 contexts

---
 FCHost/fchost/fchost_handler.cc | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/FCHost/fchost/fchost_handler.cc b/FCHost/fchost/fchost_handler.cc
index 33586d050ea..15ac430a32b 100644
--- a/FCHost/fchost/fchost_handler.cc
+++ b/FCHost/fchost/fchost_handler.cc
@@ -4,6 +4,7 @@
 
 #include "fchost_handler.h"
 
+#include <iostream>
 #include <sstream>
 #include <string>
 #include <fstream>
@@ -73,7 +74,13 @@ bool FCHostHandler::OnConsoleMessage(CefRefPtr<CefBrowser> browser, cef_log_seve
 									 const CefString& message, const CefString& source, int line)
 {
 	std::ofstream s("console.log", std::ios_base::app);
-	s << DateTime() << " - " << source.c_str() << ":" << line << ": " << message.c_str() << "\n";
+	s << DateTime() << " - ";
+    if (source.c_str()) {
+        s << source.c_str();
+    } else {
+        s << "Unknown Source";
+    }
+    s << ":" << line << ": " << message.c_str() << "\n";
 	s.flush();
 	s.close();
 
-- 
GitLab