Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
YouTube Security VideosAnonymous Official: I'm begging you to understand this..(20.09.2026 um 21:30 Uhr)
Sichere ProgrammierungHow to Monitor Cron Jobs with a Simple HTTP Health Check(20.09.2026 um 23:14 Uhr)
Sichere ProgrammierungWhy my builds don't run on my laptop(20.09.2026 um 23:15 Uhr)
Sichere ProgrammierungDesigning offline-first when there's no server(20.09.2026 um 23:16 Uhr)
Sichere ProgrammierungSearching for Better Game Recommendations with Jev(20.09.2026 um 23:19 Uhr)
Linux Tipps & HardeningUbuntu 26.10 stops low memory from killing your desktop session(20.09.2026 um 19:55 Uhr)
YouTube Security VideosAnonymous Official: I'm begging you to understand this..(20.09.2026 um 21:30 Uhr)
Sichere ProgrammierungHow to Monitor Cron Jobs with a Simple HTTP Health Check(20.09.2026 um 23:14 Uhr)
Sichere ProgrammierungWhy my builds don't run on my laptop(20.09.2026 um 23:15 Uhr)
Sichere ProgrammierungDesigning offline-first when there's no server(20.09.2026 um 23:16 Uhr)
Sichere ProgrammierungSearching for Better Game Recommendations with Jev(20.09.2026 um 23:19 Uhr)
Linux Tipps & HardeningUbuntu 26.10 stops low memory from killing your desktop session(20.09.2026 um 19:55 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

CodeSOD: Taking the Temperature

Reagiere als Erste:r — dein Feedback zählt!

Mr. TA inherited some C# code that communicates with a humidity and a temperature sensor. Each sensor logs a series of datapoints as they run, and can provide them as an array of data points.

This leads to this code:

DataPoint[] humidDataPointArray = null;  
DataPoint[] tempDataPointArray = null;

// For now,  determine if this is the primary or secondary sensor
if (sensorType == (int)SensorTypeID.HUMIDITY)
{
    // create the array size then get the data
    humidDataPointArray = new DataPoint[ttPlusData.SecondarySensorData.GetDataPoints().Count];
    humidDataPointArray = ttPlusData.SecondarySensorData.GetDataPoints().ToArray();
}
else
{
    if (sensorNum == 1)
    {
        // create the array size then get the data
        tempDataPointArray = new DataPoint[((SingleSensorTemptale)ttData).PrimarySensorData.GetDataPoints().Count];
        tempDataPointArray = ((SingleSensorTemptale)ttData).PrimarySensorData.GetDataPoints().ToArray();
    }
    else
    {
        // create the array size then get the data
        tempDataPointArray = new DataPoint[ttPlusData.SecondarySensorData.GetDataPoints().Count];
        tempDataPointArray = ttPlusData.SecondarySensorData.GetDataPoints().ToArray();
    }
}

It starts out okay. We create the arrays to hold the data. Then we check the sensorType against an enum. And that's where things start to go wrong.

We initialize an empty array that's the same size as the number of data points, then we set that array equal to the array of data points.

I'm stuck trying to figure out if this is someone with no real experience, or a C programmer trying to migrate from pointers to references. Since C# is uses references, we don't need that new- we can just set humidPointsArray equal to the result of the function call.

Speaking of the result of the function call- it looks like GetDataPoints() returns a C# enumerable type. Which implies there's really no good reason to convert it into an array. I can't be certain about that, maybe they really need the array, but I suspect that's not the case- and it's a best practice in C# to use more abstract interfaces for collections.

But it gets worse.

We have an else with an if inside of it, instead of an else if. This second condition eschews the lovely enum we used before, and just checks sensorNum == 1. Then we repeat the same unnecessary allocation, with the bonus misspelling of SingleSensorTemptale, which is certain never to give any future developer problems.

For a bonus, this code runs in a tight loop, ensuring the garbage collector gets lots of practice cleaning up memory we never needed in the first place.

[Advertisement] Keep the plebs out of prod. Restrict NuGet feed privileges with ProGet. Learn more.
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten CodeSOD: Taking the Temperature

Thematisch verwandte Begriffe: CodeSOD, Taking, Temperature · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-93956 | A flaw has been found in olivier-ls PHP-FTS up to 1.1.2. Affected by thi…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick