2 examples

Incorrect assignment

Value incorrectly assigned, causing unintended outcomes.

[ FAQ1 ]

What is incorrect assignment?

Incorrect assignment refers to bugs where a developer unintentionally assigns values incorrectly, such as assigning values to the wrong variable or using the assignment operator (=) instead of a comparison operator (== or ===) in conditional statements. These mistakes result in logic errors, unintended overwriting of values, or incorrect conditional evaluations. Such errors compromise code correctness, potentially leading to subtle bugs that can be difficult to detect and diagnose, affecting overall software reliability and functionality.
[ FAQ2 ]

How to fix incorrect assignment bugs

Incorrect assignment refers to bugs where a developer unintentionally assigns values incorrectly, such as assigning values to the wrong variable or using the assignment operator (=) instead of a comparison operator (== or ===) in conditional statements. These mistakes result in logic errors, unintended overwriting of values, or incorrect conditional evaluations. Such errors compromise code correctness, potentially leading to subtle bugs that can be difficult to detect and diagnose, affecting overall software reliability and functionality.
diff block
}
}
-export async function getClientInfo(req: NextApiRequestCollect) {
- const userAgent = req.headers['user-agent'];
- const ip = req.body?.payload?.ip || getIpAddress(req);
- const location = await getLocation(ip, req);
- const country = location?.country;
+export async function getClientInfo(request: Request, payload: Record<string, any>) {
+ const userAgent = payload?.userAgent || request.headers.get('user-agent');
+ const ip = payload?.ip || getIpAddress(request.headers);
+ const location = await getLocation(ip, request.headers);
+ const country = payload?.userAgent || location?.country;
Greptile
greptile
logic: Incorrect assignment - using payload.userAgent instead of payload.country for country value
suggested fix
+ const country = payload?.country || location?.country;
diff block
};
}, [documentId, loadDocument]);
+ const addSigningElement = useCallback(async (
+ type: SigningElement['type'],
+ position: { x: number; y: number; pageIndex: number }
+ ) => {
+ if (!documentId) return;
+
+ // Get the selected recipient's name or use the last added recipient
+ const selectedRecipient = recipients.find(r => r.id === selectedRecipientId);
+ const lastRecipient = recipients[recipients.length - 1];
+ const recipientToUse = selectedRecipient || lastRecipient;
Greptile
greptile
logic: Automatically selecting the last recipient as fallback could lead to incorrect assignments if user intended to add recipient first