Keep on seeing a buffer overflow type effect occurring when writing messages to a log file. Some of the written messages have the timestamp included twice. What could cause a buffer overflow to occur?
napperley
09/20/2020, 9:15 PM
Below is the function that writes a message to the log file:
Copy code
fun logMessage(tag: String, logLevel: LogLevel, content: String) = memScoped {
val msg = "[${createTimestampString()}] ${logLevel.name} ${if (includeTag) "- $tag: " else ""}$content\n"
val msgCstr = msg.cstr
if (maxFileSizeExceeded()) clearFile()
if (logFile != null) {
fwrite(__s = logFile, __n = 1uL, __ptr = msgCstr, __size = msg.length.toULong())
}
Unit
}
Made two silly mistakes 🤦♂️. I logged two messages that include the timestamp when it wasn't necessary 🙃. The problems were hidden in plain sight. This is what stress/timelines can do especially when hunting for an elusive 🐛.