☰ Categories

Bug Discovery Code Assistant

a Bug Discovery Code Assistant. You are an expert in software development with a keen eye for spotting bugs and inefficiencies.

CategoryDevelopment › Coding
TagsReviewingAnalyzingDeveloperCodeTemplate
Prompt
Act as a Bug Discovery Code Assistant. You are an expert in software development with a keen eye for spotting bugs and inefficiencies.
Your task is to analyze code and identify potential bugs or issues.
You will:
- Review the provided code thoroughly
- Identify any logical, syntax, or runtime errors
- Suggest possible fixes or improvements
Rules:
- Focus on both performance and security aspects
- Provide clear, concise feedback
- Use variable placeholders (e.g., ${code}) to make the prompt reusable

What this prompt does

This assigns a development assistant role that analyzes code for bugs and inefficiencies. It is written to be reusable with placeholders such as ${code}.

Model comparison

ChatGPT is the clearest and most accurate but misses the reusable-template requirement. Gemini and Claude comply more fully, though both are longer and introduce minor flaws.

ChatGPTTop overall
45/ 50

+ Delivers the clearest, most accurate, and concise review.

- It omits the requested reusable prompt using ${code}.

Claude
44/ 50

+ Provides the most code-specific security analysis, including IDOR.

- Inherited object keys can make the coupon lookup produce NaN.

Gemini
42/ 50

+ Covers the bugs, fixes, security, and reusable template.

- It is verbose, and its fix silently converts invalid values to zero.

CriterionChatGPTClaudeGeminiLeader
Instruction following81010Tie
Accuracy988ChatGPT +13%
Specificity9109Claude +11%
Structure998Tie
Right length1077ChatGPT +43%

Scored 1–10 by gpt-5.6-sol with model names hidden (2026-09-24). This is an AI review, not a measurement.

Read full answers

We gave three models the same input and copied their answers unedited. Each ran in its CLI (an agent harness), and answers in the ChatGPT or Claude apps or on the web may differ. Outputs are in Korean.

Input used
[Pasted material]
function calculateDiscount(cartItems, couponCode) {
  let total = 0;
  for (let i = 0; i <= cartItems.length; i++) {
    total += cartItems[i].price * cartItems[i].qty;
  }

  if (couponCode == "SAVE10") {
    total = total - total * 0.1;
  }

  return total;
}

async function fetchUserOrders(userId) {
  const res = fetch(`/api/orders?userId=${userId}`);
  const data = res.json();
  return data.orders;
}
gpt-5.6-luna (codex CLI · 에이전트 하네스) · Run on 2026-09-24

주요 문제점은 다음과 같습니다.

  1. calculateDiscount
  • i <= cartItems.length는 마지막 반복에서 cartItems[cartItems.length]를 참조하므로 undefined.price 오류가 발생합니다.
  • cartItems가 배열인지, 각 항목의 price와 qty가 유효한 숫자인지 검증하지 않습니다.
  • couponCode == "SAVE10"은 느슨한 비교이므로 ===를 사용하는 것이 안전합니다.
  • 금액을 부동소수점으로 계산하면 통화 오차가 발생할 수 있습니다.
  • 할인 적용은 서버 측에서도 검증해야 합니다. 클라이언트 입력만 신뢰하면 가격 조작이 가능합니다.
  1. fetchUserOrders
  • fetch()를 await하지 않아 res가 Response 객체가 아니라 Promise가 됩니다.
  • res.json()도 await하지 않아 data 역시 Promise입니다.
  • HTTP 오류(404, 500 등)를 확인하지 않습니다.
  • userId를 URL에 직접 삽입하면 특수문자로 URL이 깨질 수 있으므로 인코딩해야 합니다.
  • 인증 및 권한 검증은 서버에서 반드시 수행해야 합니다.

수정 예시는 다음과 같습니다.

function calculateDiscount(cartItems, couponCode) {
  if (!Array.isArray(cartItems)) {
    throw new TypeError("cartItems must be an array");
  }

  let total = 0;

  for (const item of cartItems) {
    if (
      !Number.isFinite(item?.price) ||
      !Number.isFinite(item?.qty) ||
      item.price < 0 ||
      item.qty < 0
    ) {
      throw new TypeError("Invalid item price or quantity");
    }

    total += item.price * item.qty;
  }

  if (couponCode === "SAVE10") {
    total *= 0.9;
  }

  return Math.round(total * 100) / 100;
}

async function fetchUserOrders(userId) {
  const params = new URLSearchParams({
    userId: String(userId),
  });

  const res = await fetch(`/api/orders?${params}`);

  if (!res.ok) {
    throw new Error(`Failed to fetch orders: ${res.status}`);
  }

  const data = await res.json();
  return data.orders;
}

실제 결제 금액이라면 부동소수점 대신 정수 단위(예: 원 또는 센트)로 계산하고, 할인율과 최종 가격은 서버에서 재계산하는 것이 좋습니다.

More in this category

12-Month AI and Computer Vision Roadmap for Defense Applications
2046 Puzzle Game Challenge
21st.dev component prompt
3D FACTORY
3D FPS Game