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 11, 2024
1 parent 8106884 commit c3119d9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 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
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
2 changes: 1 addition & 1 deletion code/modules/integrated_electronics/core/helpers.dm
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
/obj/item/integrated_circuit/proc/set_pin_data(pin_type, pin_number, datum/new_data)
if(islist(new_data))
for(var/i in 1 to length(new_data))
if (istype(new_data) && !isweakref(new_data))
if (istype(new_data[i], /datum) && !isweakref(new_data[i]))

Check warning on line 28 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 28 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_data[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
if (istype(new_data) && !isweakref(new_data))
new_data = weakref(new_data)
Expand Down

0 comments on commit c3119d9

Please sign in to comment.