Chinaunix首页 | 论坛 | 博客
  • 博客访问: 222730
  • 博文数量: 48
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 412
  • 用 户 组: 普通用户
  • 注册时间: 2013-04-24 10:27
个人简介

Continuous pursuit technical details

文章分类

全部博文(48)

文章存档

2014年(1)

2013年(47)

分类: C/C++

2013-12-03 11:33:25

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
阅读(1240) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~