minaco2 / distcc

Automatically exported from code.google.com/p/distcc
GNU General Public License v2.0
0 stars 0 forks source link

include_server crash: local variable 'resolved' referenced before assignment #99

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
distcc 3.2rc1 SVN r755, Ubuntu 11.10, gcc 4.6.1

File(s) from the linux 3.x kernel build expose include_server bug: 
include_server crashes with "local variable 'resolved' referenced before 
assignment" (log below).

Attached patch fixes the crash, but warrants further review...  Does the patch 
fully implement the intended functionality now, or is another else clause 
required (i.e. if neither 'quote' nor 'angle' matches, then what should happen?)

$ pump make -C debian/build/build-generic drivers/acpi/osl.o CC=distcc

  CC      drivers/acpi/osl.o
WARNING include server: Preprocessing locally. Include server internal error: 
'<type 'exceptions.UnboundLocalError'>: ("local variable 'resolved' referenced 
before assignment",)' for translation unit 
'/home/kamal/src/linux/ubuntu-oneiric/drivers/acpi/osl.c' ------- Include 
server stack trace -----------
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/include_server/include_server.py", line 379, in handle
    include_analyzer.client_root_keeper))
  File "/usr/lib/python2.7/site-packages/include_server/include_analyzer.py", line 260, in DoCompilationCommand
    self.ProcessCompilationCommand(currdir, parsed_command))
  File "/usr/lib/python2.7/site-packages/include_server/include_analyzer.py", line 191, in ProcessCompilationCommand
    ()))
  File "/usr/lib/python2.7/site-packages/include_server/include_analyzer.py", line 142, in _ProcessFileFromCommandLine
    closure = self.RunAlgorithm(fpath_resolved_pair, fpath_real)
  File "/usr/lib/python2.7/site-packages/include_server/include_analyzer_memoizing_node.py", line 326, in RunAlgorithm
    filepath_real_idx)
  File "/usr/lib/python2.7/site-packages/include_server/include_analyzer_memoizing_node.py", line 574, in FindNode
    self.symbol_table))
  File "/usr/lib/python2.7/site-packages/include_server/macro_eval.py", line 432, in ResolveExpr
    resolved_files.append(resolved)
UnboundLocalError: local variable 'resolved' referenced before assignment
----------------------------------------------

Original issue reported on code.google.com by kamal@whence.com on 4 Apr 2012 at 4:14

Attachments:

GoogleCodeExporter commented 9 years ago
The regular expression will always match either the 'quote' or the 'angle'.

The bug arises because the result of the match can be an empty string.
This happens e.g. if you have '#include <MACRO>' where MACRO could potentially 
evaluate to an empty string.
The code is testing
   if match_result.group('quote'):
rather than
   if match_result.group('quote') != None:
and this test fails when the match succeeds but matches an empty string.

But since an empty string can never be a valid include file name,
it is fine for the include server to exclude that possibility from its analysis.
(If the expression does actually evaluate to an empty string, the compiler will 
report an error.)

So your patch is fine.

Original comment by fergus.h...@gmail.com on 4 Apr 2012 at 6:33

Attachments:

GoogleCodeExporter commented 9 years ago
As I explained in response to another bug, I've given you commit permissions.
Please use them wisely -- make sure to get all changes reviewed and approved 
before committing.

But this change looks good, so please feel free to go and commit this fix to 
our svn repository.

Original comment by fergus.h...@gmail.com on 4 Apr 2012 at 6:51

GoogleCodeExporter commented 9 years ago

Original comment by kamal@whence.com on 4 Apr 2012 at 7:04

GoogleCodeExporter commented 9 years ago
Fix applied as SVN r759.

Original comment by kamal@whence.com on 4 Apr 2012 at 7:27