class AdLint::Exam::CBuiltin::W0637

Public Class Methods

new(phase_ctxt) click to toggle source
Calls superclass method AdLint::Examination::new
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 14938
def initialize(phase_ctxt)
  super
  interp = phase_ctxt[:cc1_interpreter]
  interp.on_function_call_expr_evaled += T(:check)
  @environ = interp.environment
end

Private Instance Methods

check(funcall_expr, fun, arg_vars, *) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 14946
def check(funcall_expr, fun, arg_vars, *)
  if fun.named? && fun.name =~ /\A.*printf\z/
    fmt = create_format(funcall_expr, format_str_index_of(funcall_expr),
                        arg_vars, @environ)
    return unless fmt

    unless fmt.extra_arguments.empty?
      if expr = find_extra_argument_expr(funcall_expr, fmt.extra_arguments)
        W(expr.location)
      else
        W(funcall_expr.location)
      end
    end
  end
end
create_format(funcall_expr, fmt_str_idx, arg_vars, env) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 14968
def create_format(funcall_expr, fmt_str_idx, arg_vars, env)
  if fmt_str_idx
    fmt_str = funcall_expr.argument_expressions[fmt_str_idx]
    if fmt_str && fmt_str.literal.value =~ /\AL?"(.*)"\z/i
      args = arg_vars.drop(fmt_str_idx + 1) || []
      return Cc1::PrintfFormat.new($1, fmt_str.location, args, env)
    end
  end
  nil
end
find_extra_argument_expr(funcall_expr, extra_args) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 14979
def find_extra_argument_expr(funcall_expr, extra_args)
  funcall_expr.argument_expressions[-extra_args.size]
end
format_str_index_of(funcall_expr) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 14962
def format_str_index_of(funcall_expr)
  funcall_expr.argument_expressions.index do |arg_expr|
    arg_expr.kind_of?(Cc1::StringLiteralSpecifier)
  end
end