From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id wMICKv2c6WZttQAAe85BDQ:P1 (envelope-from ) for ; Tue, 17 Sep 2024 17:15:09 +0200 Received: from aspmx1.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id wMICKv2c6WZttQAAe85BDQ (envelope-from ) for ; Tue, 17 Sep 2024 17:15:09 +0200 X-Envelope-To: patches@johnnyrichard.com Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=co0hlAFC; dkim=pass header.d=maniero.me header.s=hostingermail1 header.b=Hf0ByJMY; spf=pass (aspmx1.migadu.com: domain of lists@sr.ht designates 46.23.81.152 as permitted sender) smtp.mailfrom=lists@sr.ht; dmarc=pass (policy=none) header.from=maniero.me; arc=pass ("mailchannels.net:s=arc-2022:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=johnnyrichard.com; s=key1; t=1726586109; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:list-id: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=VC4gsTA4wze/mvxMfw2sZH7y+6M7nhhZf8lSdBYBv+g=; b=QzgABYcGdL9iMBRqGPypCpJR9/R3MTOA8NwTekrgBTRGRdXxNCAZ3dJ4tqaipJlgp7hGF6 J00HT2105T6ZeWwpT7WuUtVbfFqTnY1yg/9iaflaF5GNHaUrPWFMeYxaBEIEb391KTropH TOlcv6/9KYWlfgFOdQ2VOUPAJmV6X/0hXl7hNA+k2HRSzKI7wnp33eGJPAEieUMCalLRTR twqquylCihGFrzvxyP9QSH4fY/TKOxrizQKCH4H24isiASwXP6O0WHSpRj4/f6JBZLWM1w uHbky4WEPDT/FZELzJIp0buNej8yXQ2pzj/cbnK8NJZuHe3BeibnZA7vJAKSvg== ARC-Authentication-Results: i=2; aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=co0hlAFC; dkim=pass header.d=maniero.me header.s=hostingermail1 header.b=Hf0ByJMY; spf=pass (aspmx1.migadu.com: domain of lists@sr.ht designates 46.23.81.152 as permitted sender) smtp.mailfrom=lists@sr.ht; dmarc=pass (policy=none) header.from=maniero.me; arc=pass ("mailchannels.net:s=arc-2022:i=1") ARC-Seal: i=2; s=key1; d=johnnyrichard.com; t=1726586109; a=rsa-sha256; cv=pass; b=WWO7ZcSxfShrx8ygmwfm9cSzMDZUUw5D/kcLf3+CTTjxBogrJxIj0r0ECBQngjUOvviHwn iIFSUAG3SP3mcEXpWUffGhDU8Ou97FKmjmjm4Ymbfgja+rDPTeVWfxRBoHiaL3HOS8rJGV BtTbN4hC1iAg2i5juYi35a3biG6b1csl1kwVTYKYtfWcz3FdASzKi0Z54RYaL4O7/2WXkC ALafqHAsMnIJaE4+xnrSHZ2z0VzeU9yoYB8f6+p/9qRBm9InEkYL2NpXmM6Py0NSshVYCA 3Z+gz+yXFEy4qc/6TJPU0FR5KWDVy09JWk2+ZGXYDiL1KWFN12THHl8BhtzAZA== Received: from mail-a.sr.ht (mail-a.sr.ht [46.23.81.152]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 4C70AF456 for ; Tue, 17 Sep 2024 17:15:09 +0200 (CEST) DKIM-Signature: a=rsa-sha256; bh=lxcEP1j2G4pzTHxW2d61+K2dxnsXgEddnpgoCNPg6ww=; c=simple/simple; d=lists.sr.ht; h=From:To:Cc:Subject:Date:List-Unsubscribe:List-Subscribe:List-Archive:List-Post:List-ID; q=dns/txt; s=20240113; t=1726586109; v=1; b=co0hlAFCZqrQ648X6Z6esJ945TOIFlu4fQcpw8tWJEXnMCjP8CtvdLmNCdlMGhH2ilSeuwye mUl4p1GzioqRJTrNvA5RFnbaiThvIX6zYps5jR3gmoeLwr+ZE7L/4Ka1RXzAKhmomI+kxRKnFfh vjg3yIeVb+Vulhzo2QDb+lXuMj4pfKgYfYCMLo1Zu9EMaPcTXz3bVZy4kE8OOq44rCOVXayWpK0 Y+bPA+DP8uiiKkRdrqngFfgkrJTNbz6o5Qwpx9oOHe+Y7jhrPl4CAe/6dFwLVOqskaHzqFsrL03 KNT3sddREnSd2wZIfkHPZir/6glifY7u1Y1uU/o8VwK9w== Received: from lists.sr.ht (unknown [46.23.81.154]) by mail-a.sr.ht (Postfix) with ESMTPSA id 18FB22022A for ; Tue, 17 Sep 2024 15:15:09 +0000 (UTC) Received: from serval.cherry.relay.mailchannels.net (serval.cherry.relay.mailchannels.net [23.83.223.163]) by mail-a.sr.ht (Postfix) with ESMTPS id 6E1E220167 for <~johnnyrichard/olang-devel@lists.sr.ht>; Tue, 17 Sep 2024 15:15:07 +0000 (UTC) X-Sender-Id: hostingeremail|x-authuser|carlos@maniero.me Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 800724E374A for <~johnnyrichard/olang-devel@lists.sr.ht>; Tue, 17 Sep 2024 15:15:05 +0000 (UTC) Received: from fr-int-smtpout5.hostinger.io (100-96-73-205.trex-nlb.outbound.svc.cluster.local [100.96.73.205]) (Authenticated sender: hostingeremail) by relay.mailchannels.net (Postfix) with ESMTPA id D5CB84E1A9D for <~johnnyrichard/olang-devel@lists.sr.ht>; Tue, 17 Sep 2024 15:15:00 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1726586101; a=rsa-sha256; cv=none; b=+IV2XHBkc+UsPjo55I3X41hDYSQcNbZpHiEt4CPnDL+iELAIxT75FCwLbpx4dM9W1rXojY mR0S+w1tq/bXNGLrKITvfjhk6QVf4+/MVAmHqgH9n4iccwhQG6YDGIuiuYt2xk1A6MY+Tm hQxYEWx8R6t6iOMU26kLt6GR3erctzbwhadEcXPtKpFBPLHdsIbw7P1Qu6M5lKTezrlxMk d6Zm/tS0DqouUx6vvnA7M+zgeBJQPTSUi4zK9ygiSfjCGorKGtHHSbE/02WO+AZTxKzXMb Tnpran/V7jc+h5bF2rmM65iyxXpVufl8rc/3rAd6ysLlm651NydpQVyY8NXpww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1726586101; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:dkim-signature; bh=VC4gsTA4wze/mvxMfw2sZH7y+6M7nhhZf8lSdBYBv+g=; b=SQwkKH1tyuoGfzQjrI5Si3N4Fb6Mtiudr4KQIZOScUYrqRH96zcdVnML4pBoonRl2EIn7P QGFMRjQSymBLl3A0t2magqPfDusEGVMvT8utaHog1fhOLLTDz7M24m2z7bLKoo3VZ6NJKq uwhTMLKWjmbQPiCcscqg9GxWJnjhOdpOCgKuma9ZOt6ac20/HynyuPjg+mmGY5LcJC/HuJ Dd/9TRLGWGIWFeD8cnqQ8FSW6zRUmNfv19KLrBEwdaJPOFLtNuElfkd7Db84KSDkAonFi+ xsp5Ykwr9CvCWy8ZrO3Qlkd23Q3TpEfJDDzcoLplPosn5tIggZStfvx3uM52Lg== ARC-Authentication-Results: i=1; rspamd-5b46bcd97f-2pssd; auth=pass smtp.auth=hostingeremail smtp.mailfrom=carlos@maniero.me X-Sender-Id: hostingeremail|x-authuser|carlos@maniero.me X-MC-Relay: Neutral X-MailChannels-SenderId: hostingeremail|x-authuser|carlos@maniero.me X-MailChannels-Auth-Id: hostingeremail X-Stop-Belong: 01344ef676427632_1726586105311_3718704525 X-MC-Loop-Signature: 1726586105311:2377548013 X-MC-Ingress-Time: 1726586105311 Received: from fr-int-smtpout5.hostinger.io (fr-int-smtpout5.hostinger.io [89.116.146.168]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.96.73.205 (trex/7.0.2); Tue, 17 Sep 2024 15:15:05 +0000 From: Carlos Maniero DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=maniero.me; s=hostingermail1; t=1726586099; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=VC4gsTA4wze/mvxMfw2sZH7y+6M7nhhZf8lSdBYBv+g=; b=Hf0ByJMYsQq9SU2cFso1WdGxW9I76pcB3kL1tzJ9lilg76LNLSX+yUytn0BDLDCyhbCWAz cy18qVn5cDeIakO8IbUa/5URk/mtisGiYlqf8qc+Uwf5CzP5IpPwI3yMfUcCsvZJoleSC+ rXAPC0qq3yGrzJTeCxHa3xQ5EH6nV8KUfmAzcu0iVhxHCubYyRqEXFj4MmSBzvpqEiWy+e zaaxVUl9j8cTftfMGdd/9Rd6okoi2Go5NnerH1H0yLHjLonJDSMZ12tjEq08RAi9p5rYmE j+WYMA/+d0l5+1GKUhx9lGlrFRd7Pb4bhcvI4rV0/zim8n48N9rTGQ6kJuwkoQ== To: ~johnnyrichard/olang-devel@lists.sr.ht Cc: Carlos Maniero Subject: [PATCH olang] cli: add libc error handling Message-Id: <20240917151447.247230-1-carlos@maniero.me> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Date: Tue, 17 Sep 2024 15:14:58 +0000 (UTC) X-CM-Envelope: MS4xfNZny+HISwcPodidP/+ywblEgRykCCjErw1mbacn/gtGusS5UsyCxkv3yWtrBL+AkKpE6Ywqn26/1alKwl+nWrzJcHDeatfdFZ5QNFhLKajBod+MC4NK Pa/Qd8e/+OGv6LH079s2OlM+C/3sTrAmxyZrwqGS62EN7z48vFDcZmlygzr6MrcOqaABGJZqVee8Omj9Q/Kk4dYNkV/vveSdbh93WmIvCBU4b64fnzVM8oCv X-CM-Analysis: v=2.4 cv=SpTC6+O0 c=1 sm=1 tr=0 ts=66e99cf3 a=WwxFCuf3mf1fs3oSi6/dng==:117 a=WwxFCuf3mf1fs3oSi6/dng==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=dezxSmMv1Gsb6yhgeQAA:9 a=BXDaF_L80NY05PYiAFlV:22 X-AuthUser: carlos@maniero.me X-Sourcehut-Patchset-Status: PROPOSED List-Unsubscribe: List-Subscribe: List-Archive: Archived-At: List-Post: List-ID: ~johnnyrichard/olang-devel <~johnnyrichard/olang-devel.lists.sr.ht> Sender: ~johnnyrichard/olang-devel <~johnnyrichard/olang-devel@lists.sr.ht> X-Migadu-Flow: FLOW_IN X-Migadu-Country: NL X-Migadu-Spam-Score: -0.16 X-Spam-Score: -0.16 X-Migadu-Queue-Id: 4C70AF456 X-Migadu-Scanner: mx10.migadu.com X-TUID: X62JtagvU9Tw The application was ignoring libc functions result and not handling possible errors. This effort also makes the application POSIX complaint. Signed-off-by: Carlos Maniero --- src/main.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/main.c b/src/main.c index e16695b..030f34c 100644 --- a/src/main.c +++ b/src/main.c @@ -164,14 +164,24 @@ handle_codegen_linux(cli_opts_t *opts) char command[512]; sprintf(command, "%s/bin/as %s -o " SV_FMT ".o", opts->sysroot, asm_file, SV_ARG(opts->output_bin)); - system(command); + + int exit_code = system(command); + + if (exit_code != 0) { + exit(exit_code); + } sprintf(command, "%s/bin/ld " SV_FMT ".o -o " SV_FMT "", opts->sysroot, SV_ARG(opts->output_bin), SV_ARG(opts->output_bin)); - system(command); + + exit_code = system(command); + + if (exit_code != 0) { + exit(exit_code); + } if (!(opts->options & CLI_OPT_SAVE_TEMPS)) { char output_file[256]; @@ -211,7 +221,13 @@ read_entire_file(char *file_path, arena_t *arena) exit(EXIT_FAILURE); } - fread(file_content.chars, 1, file_content.size, stream); + size_t read_bytes = fread(file_content.chars, 1, file_content.size, stream); + + if (read_bytes != file_content.size) { + fprintf(stderr, "error: failed to read all file bytes %s\n", file_path); + exit(EXIT_FAILURE); + } + fclose(stream); return file_content; base-commit: 5802359caf011c960b455dcda7ce10ea794b0ea1 -- 2.34.1