Thread Tools Display Modes
09-11-12, 05:57 AM   #1
Ketho
A Pyroguard Emberseer
 
Ketho's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,026
Underscore scoping and taint

Someone provided me with a patch for the addon HideRaidFrame, saying that it would fix the taint

This is the full code (HideRaidFrame.lua)
Lua Code:
  1. -------------------------------------------
  2. --- Author: Ketho (EU-Boulderfist)      ---
  3. --- License: Public Domain              ---
  4. --- Created: 2011.07.06                 ---
  5. --- Version: 0.9 [2012.08.28]           ---
  6. -------------------------------------------
  7. --- Curse           [url]http://www.curse.com/addons/wow/hideraidframe[/url]
  8. --- WoWInterface    [url]http://www.wowinterface.com/downloads/info20052-HideRaidFrame.html[/url]
  9.  
  10. local NAME, S = ...
  11. local VERSION = 0.9
  12. local BUILD = "Release"
  13.  
  14. local ACR = LibStub("AceConfigRegistry-3.0")
  15. local ACD = LibStub("AceConfigDialog-3.0")
  16.  
  17. local L = S.L
  18.  
  19. local db
  20. local pendingReload
  21.  
  22. local function ToggleAddOn(v)
  23.     local f = (v or not db.HardDisable) and EnableAddOn or DisableAddOn
  24.     f("Blizzard_CompactRaidFrames")
  25.     f("Blizzard_CUFProfiles")
  26. end
  27.  
  28. local frames = {"Manager", "Container"}
  29.  
  30.     ---------------
  31.     --- Options ---
  32.     ---------------
  33.  
  34. local options = {
  35.     type = "group",
  36.     name = format("%s |cffADFF2Fv%s|r", NAME, VERSION),
  37.     get = function(i)
  38.         return db[i[#i]]
  39.     end,
  40.     set = function(i, v)
  41.         db[i[#i]] = v
  42.         if db.Manager or db.Container then
  43.             db.HardDisable = false
  44.         end
  45.         pendingReload = true
  46.         ToggleAddOn(db.Manager or db.Container)
  47.     end,
  48.     args = {
  49.         inline1 = {
  50.             type = "group", order = 1,
  51.             name = " ",
  52.             inline = true,
  53.             args = {
  54.                 Manager = {
  55.                     type = "toggle", order = 1,
  56.                     width = "full", descStyle = "",
  57.                     name = " "..L.RAID_MANAGER,
  58.                 },
  59.                 Container = {
  60.                     type = "toggle", order = 2,
  61.                     width = "full", descStyle = "",
  62.                     name = " "..L.RAID_CONTAINER,
  63.                 },
  64.             },
  65.         },
  66.         HardDisable = {
  67.             type = "toggle", order = 2,
  68.             desc = L.HARD_DISABLE_DESC,
  69.             name = L.HARD_DISABLE,
  70.             disabled = function() return db.Manager or db.Container end,
  71.         },
  72.         Reload = {
  73.             type = "execute", order = 3,
  74.             descStyle = "",
  75.             name = "|TInterface\\OptionsFrame\\UI-OptionsFrame-NewFeatureIcon:0:0:-2|t"..SLASH_RELOAD1,
  76.             func = ReloadUI,
  77.             hidden = function() return not pendingReload end,
  78.         },
  79.     },
  80. }
  81.  
  82.     ----------------------
  83.     --- Initialization ---
  84.     ----------------------
  85.  
  86. local f = CreateFrame("Frame")
  87.  
  88. function f:OnEvent(event, addon)
  89.     if addon ~= NAME then return end
  90.    
  91.     HideRaidFrameDB3 = HideRaidFrameDB3 or {}
  92.     db = HideRaidFrameDB3
  93.     db.version = VERSION
  94.    
  95.     ACR:RegisterOptionsTable(NAME, options)
  96.     ACD:AddToBlizOptions(NAME, NAME)
  97.     ACD:SetDefaultSize(NAME, 380, 200)
  98.    
  99.     if IsAddOnLoaded("Blizzard_CompactRaidFrames") then
  100.        
  101.         -- InCombatLockdown does not readily seem to return the correct value though
  102.         if InCombatLockdown() then print(format("|cff33FF99%s:|r %s", NAME, ERR_NOT_IN_COMBAT)) return end
  103.        
  104.         -- CompactRaidFrameManager is parented to UIParent
  105.         -- CompactRaidFrameContainer is parented to CompactRaidFrameManager
  106.         -- bug: Container (if enabled) will still be shown when solo, after leaving a raid
  107.         CompactRaidFrameContainer:SetParent(UIParent)
  108.        
  109.         for _, v in ipairs(frames) do
  110.             if not db[v] then
  111.                 local f = _G["CompactRaidFrame"..v]
  112.                 f:UnregisterAllEvents()
  113.                 f.Show = function() end
  114.                 f:Hide()
  115.             end
  116.         end
  117.     end
  118.    
  119.     ToggleAddOn(db.Manager or db.Container)
  120.     self:UnregisterEvent("ADDON_LOADED")
  121. end
  122.  
  123. f:RegisterEvent("ADDON_LOADED")
  124. f:SetScript("OnEvent", f.OnEvent)
  125.  
  126.     ---------------------
  127.     --- Slash Command ---
  128.     ---------------------
  129.  
  130. local slashCmds = {"hr", "hrf", "hideraid", "hideraidframe"}
  131.  
  132. for i, v in ipairs(slashCmds) do
  133.     _G["SLASH_HIDERAIDFRAME"..i] = "/"..v
  134. end
  135.  
  136. SlashCmdList.HIDERAIDFRAME = function(msg, editbox)
  137.     ACD:Open(NAME)
  138. end

And this is the proposed patch (line 109)
Code:
		for null, v in ipairs(frames) do
			if not db[v] then
				local f = _G["CompactRaidFrame"..v]
				f:UnregisterAllEvents()
				f.Show = function() end
				f:Hide()
			end
		end

The thing is, I don't really think it makes any difference since the underscore should be in scope to the ipairs-loop

Could anyone say if this would fix any taint?
  Reply With Quote
09-11-12, 06:28 AM   #2
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,360
That's correct (what you said).
The _ is local to the ipairs loop in this case.
  Reply With Quote
09-11-12, 06:34 AM   #3
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,360
You can try hardening your incombat check a little, because InCombatLockdown() won't return proper value if you log/relog in combat.

Best you check with:
InCombatLockdown() or UnitAffectingCombat("player") or UnitAffectingCombat("pet")
  Reply With Quote
09-11-12, 08:58 AM   #4
Barjack
A Black Drake
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 89
I always assumed InCombatLockdown() returning false when you log in during combat was intentional so as to provide a small window of opportunity to setup secure frames even while actually in combat. Is that not the case?

Regarding the use of _, my understanding is that any variables in that position will automatically be shadowed, so I wouldn't expect any difference. It may not hurt to try it just to see though, since I'm not sure how Blizzard's taint system works under the hood.

Last edited by Barjack : 09-11-12 at 09:01 AM.
  Reply With Quote
09-11-12, 10:07 AM   #5
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
The patch is inconsequential. Variables declared in a loop are local to the loop, so the underscore never references the global version.
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Underscore scoping and taint


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off