Skip to content

Commit

Permalink
Fix a bunch of SAST issues
Browse files Browse the repository at this point in the history
  • Loading branch information
NorseDreki committed May 21, 2024
1 parent 0755674 commit 8c463fd
Showing 8 changed files with 24 additions and 18 deletions.
10 changes: 8 additions & 2 deletions src/commonMain/kotlin/com/norsedreki/logger/CanLog.kt
Original file line number Diff line number Diff line change
@@ -6,13 +6,19 @@
package com.norsedreki.logger

interface CanLog {

fun d(line: String)

fun close()
}

class NoOpLogger : CanLog {
override fun d(line: String) {}

override fun close() {}
override fun d(line: String) {
// Expected to do nothing
}

override fun close() {
// Expected to do nothing
}
}
8 changes: 4 additions & 4 deletions src/commonMain/kotlin/com/norsedreki/logger/Logger.kt
Original file line number Diff line number Diff line change
@@ -7,17 +7,17 @@ package com.norsedreki.logger

object Logger : CanLog {

private lateinit var logger: CanLog
private lateinit var canLog: CanLog

fun set(l: CanLog) {
logger = l
canLog = l
}

override fun d(line: String) {
logger.d(line)
canLog.d(line)
}

override fun close() {
logger.close()
canLog.close()
}
}
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@

package com.norsedreki.dogcat.app

import com.norsedreki.dogcat.DogcatException
import com.norsedreki.dogcat.app.AppConfig.APP_LOG_FILENAME
import com.norsedreki.logger.CanLog
import kotlinx.cinterop.CPointer
@@ -21,7 +22,7 @@ class FileLogger : CanLog {
// I/O is not cool for field initializers, but would be OK when debugging
private val file: CPointer<FILE> =
fopen(APP_LOG_FILENAME, "w")
?: throw RuntimeException("Was not able to open log file for writing.")
?: throw DogcatException("Was not able to open log file for writing.")

override fun d(line: String) {
fprintf(file, "$line\n")
1 change: 0 additions & 1 deletion src/nativeMain/kotlin/com/norsedreki/dogcat/app/Main.kt
Original file line number Diff line number Diff line change
@@ -42,7 +42,6 @@ fun main(args: Array<String>) {
}

if (appModule.appArguments.version == true) {
// val c = '\u2026'
val c = '\u2026'

val m =
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ import com.norsedreki.dogcat.app.AppState
import com.norsedreki.dogcat.app.BuildConfig
import com.norsedreki.dogcat.app.FileLogger
import com.norsedreki.dogcat.app.InternalAppState
import com.norsedreki.dogcat.app.di.DogcatModule.dogcatModule
import com.norsedreki.dogcat.app.di.DogcatModule.dogcat
import com.norsedreki.dogcat.app.ui.DefaultInput
import com.norsedreki.dogcat.app.ui.Input
import com.norsedreki.dogcat.app.ui.app.AppPresenter
@@ -25,7 +25,7 @@ import org.kodein.di.instance

class AppModule {

private val appModule =
private val app =
DI.Module("app") {
bindSingleton<CanLog> {
if (BuildConfig.DEBUG) {
@@ -65,8 +65,8 @@ class AppModule {
}

private val serviceLocator = DI {
import(dogcatModule)
import(appModule)
import(dogcat)
import(app)
}

val fileLogger: CanLog by serviceLocator.instance()
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ import org.kodein.di.instance

object DogcatModule {

internal val dogcatModule =
internal val dogcat =
DI.Module("dogcat") {
bindSingleton<LogFiltersState> { DefaultLogFiltersState() }
bindSingleton<LogLineParser> { LogLineBriefParser() }
Original file line number Diff line number Diff line change
@@ -62,10 +62,8 @@ private fun LogLinesView.refreshPrintedLine(numLinesOnScreen: Int) {
lineDown(numLinesOnScreen) // batch calls in order not to draw each line
}
} else {
if (state.overscroll) {
if (firstVisibleLine >= numLinesOnScreen) {
firstVisibleLine -= numLinesOnScreen
}
if (state.overscroll && firstVisibleLine >= numLinesOnScreen) {
firstVisibleLine -= numLinesOnScreen
}
refresh()
}
Original file line number Diff line number Diff line change
@@ -57,7 +57,9 @@ class StatusPresenter(
.collect {
val filters = it.filters.first()

filters[ByPackage::class]?.let { appState.filterByPackage(it as ByPackage, true) }
filters[ByPackage::class]?.let { filter ->
appState.filterByPackage(filter as ByPackage, true)
}

view.state =
view.state.copy(

0 comments on commit 8c463fd

Please sign in to comment.