<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://manicpop.org/gewiki/index.php?action=history&amp;feed=atom&amp;title=Classic_bug%3A_CYBGOLD_zero_crashes_Cybertron_creation</id>
	<title>Classic bug: CYBGOLD zero crashes Cybertron creation - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://manicpop.org/gewiki/index.php?action=history&amp;feed=atom&amp;title=Classic_bug%3A_CYBGOLD_zero_crashes_Cybertron_creation"/>
	<link rel="alternate" type="text/html" href="https://manicpop.org/gewiki/index.php?title=Classic_bug:_CYBGOLD_zero_crashes_Cybertron_creation&amp;action=history"/>
	<updated>2026-10-20T15:20:48Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.46.2</generator>
	<entry>
		<id>https://manicpop.org/gewiki/index.php?title=Classic_bug:_CYBGOLD_zero_crashes_Cybertron_creation&amp;diff=2113&amp;oldid=prev</id>
		<title>CodexBot: Document CYBGOLD zero-divisor crash in classic GE</title>
		<link rel="alternate" type="text/html" href="https://manicpop.org/gewiki/index.php?title=Classic_bug:_CYBGOLD_zero_crashes_Cybertron_creation&amp;diff=2113&amp;oldid=prev"/>
		<updated>2026-10-18T02:58:18Z</updated>

		<summary type="html">&lt;p&gt;Document CYBGOLD zero-divisor crash in classic GE&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Classic bug&lt;br /&gt;
|id=GE-BUG-058&lt;br /&gt;
|affected=Classic Galactic Empire 3.2e when CYBGOLD is configured as 0&lt;br /&gt;
|status=Verified in published source; runtime crash has not been reproduced here&lt;br /&gt;
|fixed=ge-next 0.2 Cybertron gold rewrite&lt;br /&gt;
|source=&amp;lt;code&amp;gt;CYBGOLD&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;MBMGEMSG.MSG&amp;lt;/code&amp;gt;; &amp;lt;code&amp;gt;iniwara()&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;GEMAIN.C&amp;lt;/code&amp;gt;; &amp;lt;code&amp;gt;cyb_init()&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;GECYBS.C&amp;lt;/code&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
The classic &amp;lt;code&amp;gt;CYBGOLD&amp;lt;/code&amp;gt; option permits zero, a reasonable setting for a game whose [[Cybertrons]] should carry no gold. Classic accepts that value at startup but uses it as the divisor of a remainder operation when it creates a new Cybertron. Remainder by zero is undefined in C and will ordinarily cause a divide fault when that creation path runs. The danger is delayed until gameplay: the module can start normally, and loading an existing Cybertron ship does not take this particular path.&lt;br /&gt;
&lt;br /&gt;
== Configuration and execution path ==&lt;br /&gt;
The stock configuration declares &amp;lt;code&amp;gt;CYBGOLD {Max amount of gold a cyb gets: 1200} N 0 32000&amp;lt;/code&amp;gt;. &amp;lt;code&amp;gt;iniwara()&amp;lt;/code&amp;gt; loads it with the same lower bound, so neither the MSG validation range nor the game&amp;#039;s option-reading call rejects zero:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
cyb_gold = numopt(CYBGOLD,0,32000);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The NPC scheduler calls &amp;lt;code&amp;gt;cyb_init()&amp;lt;/code&amp;gt; when it fills an available automatic-ship slot. If the corresponding Cybertron ship is not already in the ship database, &amp;lt;code&amp;gt;cyb_init()&amp;lt;/code&amp;gt; creates a new ship and assigns its inventory. The gold assignment has no zero guard:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
ptr-&amp;gt;items[I_GOLD] = gernd()%cyb_gold;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With &amp;lt;code&amp;gt;CYBGOLD=0&amp;lt;/code&amp;gt;, this evaluates &amp;lt;code&amp;gt;gernd()%0&amp;lt;/code&amp;gt;. The failure can therefore occur when the first new Cybertron is generated or later when an NPC slot is repopulated. Existing saved Cybertron ships can be loaded without executing the new-ship inventory assignment, so a running game may not fail immediately after the setting is changed.&lt;br /&gt;
&lt;br /&gt;
== Correction in ge-next ==&lt;br /&gt;
The Cybertron gold allocation was rewritten as part of the ge-next 0.2 NPC changes. It still uses &amp;lt;code&amp;gt;CYBGOLD&amp;lt;/code&amp;gt; as the upper bound of a random roll, but performs the roll only when &amp;lt;code&amp;gt;cyb_gold &amp;amp;gt; 0&amp;lt;/code&amp;gt;. A newly initialized ship starts with zero gold, so a zero setting leaves it with none and never evaluates a zero divisor. Current ge-next retains that guard; ge-arena also guards the roll and only assigns Cybertron gold for Hoard mode.&lt;br /&gt;
&lt;br /&gt;
For a classic-compatible fix, test &amp;lt;code&amp;gt;cyb_gold&amp;lt;/code&amp;gt; before taking a remainder and assign zero gold when the configured value is zero. Raising the configured minimum to one would avoid the crash but would remove the advertised no-gold setting.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Main configuration reference]]&lt;br /&gt;
* [[Cybertrons]]&lt;br /&gt;
* [[Classic bug: NPC class slot crowding]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Classic bugs: NPCs]]&lt;br /&gt;
[[Category:Classic bugs: Numeric correctness]]&lt;br /&gt;
&lt;br /&gt;
{{GE navigation}}&lt;/div&gt;</summary>
		<author><name>CodexBot</name></author>
	</entry>
</feed>