Skip to content

Commit

Permalink
Fix code that indexes datum-typed variables
Browse files Browse the repository at this point in the history
  • Loading branch information
out-of-phaze committed Jul 12, 2024
1 parent 8106884 commit 3ea25cd
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 32 deletions.
11 changes: 6 additions & 5 deletions code/_helpers/logging.dm
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,13 @@ var/global/log_end= world.system_type == UNIX ? ascii2text(13) : ""
if(isnull(d))
return "*null*"
if(islist(d))
var/list/L = list()
for(var/e in d)
var/list/out = list()
var/list/dlist = d
for(var/entry in dlist)
// Indexing on numbers just gives us the same number again in the best case and causes an index out of bounds runtime in the worst
var/v = isnum(e) ? null : d[e]
L += "[log_info_line(e)][" - [log_info_line(v)]"]"
return "\[[jointext(L, ", ")]\]" // We format the string ourselves, rather than use json_encode(), because it becomes difficult to read recursively escaped "
var/value = isnum(entry) ? null : dlist[entry]
out += "[log_info_line(entry)][" - [log_info_line(value)]"]"
return "\[[jointext(out, ", ")]\]" // We format the string ourselves, rather than use json_encode(), because it becomes difficult to read recursively escaped "
if(!istype(d))
return json_encode(d)
return d.get_log_info_line()
Expand Down
13 changes: 7 additions & 6 deletions code/controllers/subsystems/overlays.dm
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,13 @@ SUBSYSTEM_DEF(overlays)
/atom/proc/build_appearance_list(atom/new_overlays)
var/static/image/appearance_bro = new
if(islist(new_overlays))
if(null in new_overlays)
new_overlays -= new /list(length(new_overlays)) // Clears nulls from the list prior to appearancifying.
for(var/i in 1 to length(new_overlays))
var/image/cached_overlay = new_overlays[i]
APPEARANCEIFY(cached_overlay, new_overlays[i])
return new_overlays
var/list/new_overlays_list = new_overlays
if(null in new_overlays_list)
new_overlays_list -= new /list(length(new_overlays_list)) // Clears nulls from the list prior to appearancifying.
for(var/i in 1 to length(new_overlays_list))
var/image/cached_overlay = new_overlays_list[i]
APPEARANCEIFY(cached_overlay, new_overlays_list[i])
return new_overlays_list
else
APPEARANCEIFY(new_overlays, .)

Expand Down
7 changes: 4 additions & 3 deletions code/modules/character_info/character_info_interface.dm
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@
return

if(islist(comments))
if(length(comments) == 1)
comments = comments[1]
var/list/comment_list = comments
if(length(comment_list) == 1)
comments = comment_list[1]
else
comments = input(usr, "Multiple matches. Which character do you wish to show?", "View Character Comments") as null|anything in comments
comments = input(usr, "Multiple matches. Which character do you wish to show?", "View Character Comments") as null|anything in comment_list
if(istype(comments))
comments.display_to(usr)
else
Expand Down
16 changes: 10 additions & 6 deletions code/modules/integrated_electronics/core/helpers.dm
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@

/obj/item/integrated_circuit/proc/set_pin_data(pin_type, pin_number, datum/new_data)
if(islist(new_data))
var/datum/new_list = new_data
for(var/i in 1 to length(new_data))
if (istype(new_data) && !isweakref(new_data))
new_data[i] = weakref(new_data[i])
if (istype(new_list[i], /datum) && !isweakref(new_list[i]))

Check warning on line 29 in code/modules/integrated_electronics/core/helpers.dm

View workflow job for this annotation

GitHub Actions / OpenDream

OD2304: Invalid index operation. datum[] index operations are not valid starting in BYOND 515.1641

Check warning on line 29 in code/modules/integrated_electronics/core/helpers.dm

View workflow job for this annotation

GitHub Actions / OpenDream

OD2304: Invalid index operation. datum[] index operations are not valid starting in BYOND 515.1641
new_data[i] = weakref(new_list[i])

Check warning on line 30 in code/modules/integrated_electronics/core/helpers.dm

View workflow job for this annotation

GitHub Actions / OpenDream

OD2304: Invalid index operation. datum[] index operations are not valid starting in BYOND 515.1641

Check warning on line 30 in code/modules/integrated_electronics/core/helpers.dm

View workflow job for this annotation

GitHub Actions / OpenDream

OD2304: Invalid index operation. datum[] index operations are not valid starting in BYOND 515.1641
if (istype(new_data) && !isweakref(new_data))
new_data = weakref(new_data)
var/datum/integrated_io/pin = get_pin_ref(pin_type, pin_number)
Expand Down Expand Up @@ -62,10 +63,13 @@

/datum/integrated_io/proc/get_data()
if(islist(data))
for(var/i in 1 to length(data))
if(isweakref(data[i]))
var/weakref/dw = data[i]
data[i] = dw.resolve()
var/list/data_list = data
data_list = data_list.Copy()
for(var/i in 1 to length(data_list))
if(isweakref(data_list[i]))
var/weakref/dw = data_list[i]
data_list[i] = dw.resolve()
return data_list
if(isweakref(data))
return data.resolve()
return data
Expand Down
6 changes: 3 additions & 3 deletions code/modules/mob/mob_helpers.dm
Original file line number Diff line number Diff line change
Expand Up @@ -534,9 +534,9 @@ var/global/list/intents = list(I_HELP,I_DISARM,I_GRAB,I_HURT)
return !client && !teleop && (last_ckey || !ai)

/mob/proc/try_teleport(var/area/thearea)
if(!istype(thearea))
if(istype(thearea, /list))
thearea = thearea[1]
if(istype(thearea, /list))
var/list/area_list = thearea
thearea = area_list[1]
var/list/L = list()
for(var/turf/T in get_area_turfs(thearea))
if(!T.density)
Expand Down
17 changes: 9 additions & 8 deletions code/modules/modular_computers/hardware/nano_printer.dm
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,14 @@
if(stored_paper >= max_paper) //check if the printer is full yet
to_chat(user, "The printer has been filled to full capacity.")
break
if(B.pages.len == 0) //if all its papers have been put into the printer, delete bundle
qdel(W)
else if(B.pages.len == 1) //if only one item left, extract item and delete the one-item bundle
user.drop_from_inventory(B)
user.put_in_hands(B[1])
qdel(B)
else //if at least two items remain, just update the bundle icon
B.update_icon()
switch(length(B.pages))
if(0) //if all its papers have been put into the printer, delete bundle
qdel(B)
if(1) //if only one item left, extract item and delete the one-item bundle
user.drop_from_inventory(B)
user.put_in_hands(B.pages[1])
qdel(B)
else //if at least two items remain, just update the bundle icon
B.update_icon()
to_chat(user, "You add [num_of_pages_added] papers from \the [W] into \the [src].")
return
3 changes: 2 additions & 1 deletion code/modules/spells/general/contract_spells.dm
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
return null

if(istype(target,/list))
target = target[1]
var/list/target_list = target
target = target_list[1]
return target


Expand Down

0 comments on commit 3ea25cd

Please sign in to comment.