From 8ba557db917cce0b3f95a5fac530f2d7d2c6ab4c Mon Sep 17 00:00:00 2001 From: David Mandelin Date: Tue, 1 Jul 2008 15:31:10 -0700 Subject: [PATCH] Bug 442968: fix small bug with void returns in outparams.js, r=bsmedberg --- xpcom/analysis/outparams.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/xpcom/analysis/outparams.js b/xpcom/analysis/outparams.js index 68d2c6c43268..0b90d412624f 100644 --- a/xpcom/analysis/outparams.js +++ b/xpcom/analysis/outparams.js @@ -563,6 +563,28 @@ OutparamCheck.prototype.checkSubstate = function(isvoid, fndecl, ss) { } } +/* @return The return statement in the function + * that writes the return value in the given substate. + * If the function returns void, then the substate doesn't + * matter and we just look for the return. */ +OutparamCheck.prototype.findReturnStmt = function(ss) { + if (this.retvar != undefined) + return ss.getBlame(this.retvar); + + if (this.cfg._cached_return) + return this.cfg._cached_return; + + for (let bb in cfg_bb_iterator(this.cfg)) { + for (let isn in bb_isn_iterator(bb)) { + if (TREE_CODE(isn) == RETURN_EXPR) { + return this.cfg._cached_return = isn; + } + } + } + + return undefined; +} + OutparamCheck.prototype.checkSubstateSuccess = function(ss) { for (let i = 0; i < this.psem_list.length; ++i) { let [v, psem] = [ this.outparam_list[i], this.psem_list[i] ]; @@ -570,7 +592,7 @@ OutparamCheck.prototype.checkSubstateSuccess = function(ss) { let val = ss.get(v); if (val == av.NOT_WRITTEN) { this.logResult('succ', 'not_written', 'error'); - this.warn([ss.getBlame(this.retvar), "outparam '" + expr_display(v) + "' not written on NS_SUCCEEDED(return value)"], + this.warn([this.findReturnStmt(ss), "outparam '" + expr_display(v) + "' not written on NS_SUCCEEDED(return value)"], [v, "outparam declared here"]); } else if (val == av.MAYBE_WRITTEN) { this.logResult('succ', 'maybe_written', 'error'); @@ -604,7 +626,7 @@ OutparamCheck.prototype.checkSubstateFailure = function(ss) { let val = ss.get(v); if (val == av.WRITTEN) { this.logResult('fail', 'written', 'error'); - this.warn([ss.getBlame(this.retvar), "outparam '" + expr_display(v) + "' written on NS_FAILED(return value)"], + this.warn([this.findReturnStmt(ss), "outparam '" + expr_display(v) + "' written on NS_FAILED(return value)"], [v, "outparam declared here"], [ss.getBlame(v), "written here"]); } else if (val == av.WROTE_NULL) {