1. Misuse of "=" and "==" (equals and compare) in if condition
2. Use gcc warning to detect potential issues (e.g. too many arguments)
3. Buffer overflow, ending of an array, '\0' is needed.
4. Memory issue (deallocate, leak)
Solution
=======================1=====================
#! /usr/bin/python
import sys
import glob
import string
import os
if len(sys.argv) < 2:
print 'format is MemTrace2Csv.py Mem-Trace- Out'
sys.exit()
search_str = sys.argv[1] #it should be if while for
#pre_fix = sys.argv[2]
#file_list = sys.argv[3] #the file which includes all the source code file
#list = open(file_list, 'r')
cur_str = ' ' #the string which would be analysis
cnt_left = 0 # the count of '(' in the cur_str
cnt_right = 0 # the count of ')' in the cur_str
is_exit = False
search_1 = search_str+"("
search_2 = search_str+" ("
cur_line = 0 #the cur line # of the cur file
while True:
# file_name = list.readline()
# if not file_name:
# break
# file_name = file_name.strip() #remove the \n
# file_name = pre_fix+file_name[1:len(file_name)] #drop the first .
# print "%s" %(file_name)
cur_file = open("/fs/umtsbld/R2808.00/ssp/ds/ims/s_cscf/near/CPscscf_tcm_util.cpp", 'r')
cur_line=0 #reset the line # because of starting a new file
while True:
oneLine = cur_file.readline()
print oneLine
cur_line = cur_line + 1
if not oneLine:
break
search_str = search_str+"("
is_if = oneLine.find(search_1) # this line include if condition
if is_if == -1:
is_if = oneLine.find(search_2)
if is_if != -1:
oneLine.strip()
cur_str = oneLine
cnt_left = cur_str.count('(');
cnt_right = cur_str.count(')');
while cnt_left != cnt_right: # for some if condition it invloved multiple lines. need to find the whole condition
oneLine = cur_file.readline()
oneLine = oneLine.strip()
cur_line = cur_line + 1
if not oneLine:
is_exit = True
break
cur_str = cur_str + oneLine
cnt_left = cur_str.count('(');
cnt_right = cur_str.count(')');
for i in range (len(cur_str)):
if cur_str[i] == '=':
if cur_str[i-1] == '>' or cur_str[i-1] == '<' or cur_str[i-1] == '!' or cur_str[i-1] == '=' or cur_str[i+1] == '=':
#do nothing
i=i+1
else:
print "line # is %d %s"%(cur_line,cur_str)
break
#for i in os.popen('echo $cur_str|grep "=" |grep -v "==" | grep -v ">=" |grep -v "<=" |grep -v "!="'):
if is_exit == True:
break
break
===========2===========
to be continued
阅读(1289) | 评论(0) | 转发(0) |