Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to lts-22 and remove sprintf #1461

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions core/carp_pattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ String Pattern_internal_match(PatternMatchState *ms, String s, String p) {
if (s) {
p += 4;
goto init; /* return match(ms, s, p + 4); */
} /* else fail (s == NULL) */
} /* else fail (s == NULL) */
break;
}
case 'f': { /* frontier? */
Expand Down Expand Up @@ -341,7 +341,7 @@ String Pattern_internal_match(PatternMatchState *ms, String s, String p) {
break;
}
default:
dflt : { /* Pattern class plus optional suffix */
dflt: { /* Pattern class plus optional suffix */
String ep = Pattern_internal_classend(
ms, p); /* points to optional suffix */
/* does not match at least once? */
Expand Down Expand Up @@ -568,13 +568,13 @@ Array Pattern_match_MINUS_all_MINUS_groups(Pattern *p, String *s) {
String Pattern_internal_add_char(String a, Char b) {
if (!a) {
String buffer = CARP_MALLOC(2);
snprintf(buffer, 1, "%c", b);
snprintf(buffer, 2, "%c", b);
return buffer;
}

int len = strlen(a) + 2;
String buffer = CARP_MALLOC(len);
snprintf(buffer, len-1, "%s%c", a, b);
snprintf(buffer, len, "%s%c", a, b);
CARP_FREE(a);
return buffer;
}
Expand Down Expand Up @@ -645,7 +645,7 @@ String Pattern_substitute(Pattern *p, String *s, String *t, int ns) {

int l = strlen(res) + strlen(str) + 1;
String buffer = CARP_MALLOC(l);
snprintf(buffer, l-1, "%s%s", res, str);
snprintf(buffer, l, "%s%s", res, str);
CARP_FREE(res);
return buffer;
}
Expand All @@ -671,7 +671,7 @@ String Pattern_str(Pattern *p) {
String Pattern_prn(Pattern *p) {
int n = strlen(*p) + 4;
String buffer = CARP_MALLOC(n);
snprintf(buffer, n-1, "#\"%s\"", *p);
snprintf(buffer, n, "#\"%s\"", *p);
return buffer;
}

Expand Down
28 changes: 14 additions & 14 deletions core/carp_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ char String_char_MINUS_at(const String *s, int i) {
String String_format(const String *str, const String *s) {
int size = snprintf(NULL, 0, *str, *s) + 1;
String buffer = CARP_MALLOC(size);
sprintf(buffer, *str, *s);
snprintf(buffer, size, *str, *s);
return buffer;
}

Expand Down Expand Up @@ -230,7 +230,7 @@ String Bool_str(bool b) {
String Bool_format(const String *str, bool b) {
int size = snprintf(NULL, 0, *str, b) + 1;
String buffer = CARP_MALLOC(size);
sprintf(buffer, *str, b);
snprintf(buffer, size, *str, b);
return buffer;
}

Expand Down Expand Up @@ -258,21 +258,21 @@ String Char_prn(Char c) {
String Char_format(const String *str, char b) {
int size = snprintf(NULL, 0, *str, b) + 1;
String buffer = CARP_MALLOC(size);
sprintf(buffer, *str, b);
snprintf(buffer, size, *str, b);
return buffer;
}

String Double_str(double x) {
int size = snprintf(NULL, 0, "%g", x) + 1;
String buffer = CARP_MALLOC(size);
sprintf(buffer, "%g", x);
snprintf(buffer, size, "%g", x);
return buffer;
}

String Double_format(const String *s, double x) {
int size = snprintf(NULL, 0, *s, x) + 1;
String buffer = CARP_MALLOC(size);
sprintf(buffer, *s, x);
snprintf(buffer, size, *s, x);
return buffer;
}

Expand All @@ -285,14 +285,14 @@ bool Double_from_MINUS_string_MINUS_internal(const String *s, double *target) {
String Float_str(float x) {
int size = snprintf(NULL, 0, "%gf", x) + 1;
String buffer = CARP_MALLOC(size);
sprintf(buffer, "%gf", x);
snprintf(buffer, size, "%gf", x);
return buffer;
}

String Float_format(const String *str, float x) {
int size = snprintf(NULL, 0, *str, x) + 1;
String buffer = CARP_MALLOC(size);
sprintf(buffer, *str, x);
snprintf(buffer, size, *str, x);
return buffer;
}

Expand All @@ -305,14 +305,14 @@ bool Float_from_MINUS_string_MINUS_internal(const String *s, float *target) {
String Int_str(int x) {
int size = snprintf(NULL, 0, "%d", x) + 1;
String buffer = CARP_MALLOC(size);
sprintf(buffer, "%d", x);
snprintf(buffer, size, "%d", x);
return buffer;
}

String Int_format(const String *str, int x) {
int size = snprintf(NULL, 0, *str, x) + 1;
String buffer = CARP_MALLOC(size);
sprintf(buffer, *str, x);
snprintf(buffer, size, *str, x);
return buffer;
}

Expand All @@ -325,14 +325,14 @@ bool Int_from_MINUS_string_MINUS_internal(const String *s, int *target) {
String Long_str(Long x) {
int size = snprintf(NULL, 0, "%" PRIi64, x) + 1;
String buffer = CARP_MALLOC(size);
sprintf(buffer, "%" PRIi64, x);
snprintf(buffer, size, "%" PRIi64, x);
return buffer;
}

String Long_format(const String *str, Long x) {
int size = snprintf(NULL, 0, *str, x) + 1;
String buffer = CARP_MALLOC(size);
sprintf(buffer, *str, x);
snprintf(buffer, size, *str, x);
return buffer;
}

Expand All @@ -345,14 +345,14 @@ bool Long_from_MINUS_string_MINUS_internal(const String *s, Long *target) {
String Byte_str(uint8_t x) {
int size = snprintf(NULL, 0, "%ub", x) + 1;
String buffer = CARP_MALLOC(size);
sprintf(buffer, "%ub", x);
snprintf(buffer, size, "%ub", x);
return buffer;
}

String Byte_format(const String *str, uint8_t x) {
int size = snprintf(NULL, 0, *str, x) + 1;
String buffer = CARP_MALLOC(size);
sprintf(buffer, *str, x);
snprintf(buffer, size, *str, x);
return buffer;
}

Expand Down Expand Up @@ -386,6 +386,6 @@ int String_index_MINUS_of(const String *s, char c) {
String Pointer_strp(void *in) {
int size = snprintf(NULL, 0, "%p", in) + 1;
String buffer = CARP_MALLOC(size);
sprintf(buffer, "%p", in);
snprintf(buffer, size, "%p", in);
return buffer;
}
6 changes: 3 additions & 3 deletions src/ArrayTemplates.hs
Original file line number Diff line number Diff line change
Expand Up @@ -669,15 +669,15 @@ strTy typeEnv env (StructTy _ [innerType]) =
TokC " String buffer = CARP_MALLOC(size);\n",
TokC " String bufferPtr = buffer;\n",
TokC "\n",
TokC " sprintf(buffer, \"[\");\n",
TokC " snprintf(buffer, size, \"[\");\n",
TokC " bufferPtr += 1;\n",
TokC "\n",
TokC " for(int i = 0; i < a->len; i++) {\n",
TokC $ " " ++ insideArrayStr typeEnv env innerType,
TokC " }\n",
TokC "\n",
TokC " if(a->len > 0) { bufferPtr -= 1; }\n",
TokC " sprintf(bufferPtr, \"]\");\n",
TokC " snprintf(bufferPtr, size - (bufferPtr - buffer), \"]\");\n",
TokC " return buffer;\n"
]
strTy _ _ _ = []
Expand Down Expand Up @@ -729,7 +729,7 @@ insideArrayStr typeEnv env t =
FunctionFound functionFullName ->
unlines
[ " temp = " ++ strcall functionFullName,
" sprintf(bufferPtr, \"%s \", temp);",
" snprintf(bufferPtr, size - (bufferPtr - buffer), \"%s \", temp);",
" bufferPtr += strlen(temp) + 1;",
" if(temp) {",
" CARP_FREE(temp);",
Expand Down
8 changes: 4 additions & 4 deletions src/BoxTemplates.hs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ prn =
[ "$DECL {",
" if(!box){",
" String buffer = CARP_MALLOC(4);",
" sprintf(buffer, \"Nil\");",
" snprintf(buffer, 4, \"Nil\");",
" return buffer;",
" }",
innerStr tenv env boxT,
Expand Down Expand Up @@ -231,7 +231,7 @@ str =
[ "$DECL {",
" if(!box){",
" String buffer = CARP_MALLOC(4);",
" sprintf(buffer, \"Nil\");",
" snprintf(buffer, 4, \"Nil\");",
" return buffer;",
" }",
innerStr tenv env boxT,
Expand All @@ -257,7 +257,7 @@ innerStr tenv env (StructTy _ [t]) =
[ " char* temp = " ++ functionFullName ++ "(*box);",
" int size = snprintf(NULL, 0, \"(Box %s)\", temp);",
" String buffer = CARP_MALLOC(size);",
" sprintf(buffer, \"(Box %s)\", temp);",
" snprintf(buffer, size, \"(Box %s)\", temp);",
" if(temp) {",
" CARP_FREE(temp);",
" temp = NULL;",
Expand All @@ -266,7 +266,7 @@ innerStr tenv env (StructTy _ [t]) =
FunctionNotFound _ ->
unlines
[ " String buffer = CARP_MALLOC(14);",
" sprintf(buffer, \"(Box unknown)\");"
" snprintf(buffer, 14, \"(Box unknown)\");"
]
FunctionIgnored -> " /* Ignore type inside Box: '" ++ show t ++ "' ??? */\n"
innerStr _ _ _ = ""
1 change: 1 addition & 0 deletions src/Concretize.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ where
import AssignTypes
import Constraints
import Control.Applicative
import Control.Monad (foldM, unless)
import Control.Monad.State
import Data.Either (fromRight)
import Data.List (foldl')
Expand Down
4 changes: 2 additions & 2 deletions src/Deftype.hs
Original file line number Diff line number Diff line change
Expand Up @@ -509,11 +509,11 @@ strGenerator = TG.mkTemplateGenerator genT decl body deps
" String buffer = CARP_MALLOC(size);",
" String bufferPtr = buffer;",
"",
" sprintf(bufferPtr, \"(%s \", \"" ++ typeName ++ "\");",
" snprintf(bufferPtr, size - (bufferPtr - buffer), \"(%s \", \"" ++ typeName ++ "\");",
" bufferPtr += strlen(\"" ++ typeName ++ "\") + 2;\n",
joinLines (map (memberPrn typeEnv env) members),
" bufferPtr--;",
" sprintf(bufferPtr, \")\");",
" snprintf(bufferPtr, size - (bufferPtr - buffer), \")\");",
" return buffer;",
"}"
]
Expand Down
1 change: 1 addition & 0 deletions src/Emit.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module Emit
)
where

import Control.Monad (unless, when, zipWithM_)
import Control.Monad.State
import Data.Char (ord)
import Data.Functor ((<&>))
Expand Down
1 change: 1 addition & 0 deletions src/Eval.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Commands
import Context
import Control.Applicative
import Control.Exception
import Control.Monad (foldM, when)
import Control.Monad.State
import Data.Either (fromRight)
import Data.Foldable (foldlM, foldrM)
Expand Down
2 changes: 1 addition & 1 deletion src/GenerateConstraints.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module GenerateConstraints (genConstraints) where

import Constraints
import Control.Arrow hiding (arr)
import Control.Monad.State
import Control.Monad (join)
import Data.List as List
import Data.Maybe (catMaybes, fromMaybe, mapMaybe)
import Info
Expand Down
1 change: 1 addition & 0 deletions src/InitialTypes.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module InitialTypes where

import Control.Monad (foldM, join, replicateM)
import Control.Monad.State
import Data.Either (fromRight)
import Env as E
Expand Down
1 change: 1 addition & 0 deletions src/Obj.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
module Obj where

import Control.Applicative
import Control.Monad (zipWithM)
import Control.Monad.State
import Data.Char
import Data.Hashable
Expand Down
4 changes: 2 additions & 2 deletions src/StructUtils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ memberPrn typeEnv env (memberName, memberTy) =
(FuncTy [UnitTy] _ _) ->
unlines
[ " temp = " ++ pathToC strFunctionPath ++ "();",
" sprintf(bufferPtr, \"%s \", temp);",
" snprintf(bufferPtr, size - (bufferPtr - buffer), \"%s \", temp);",
" bufferPtr += strlen(temp) + 1;",
" if(temp) { CARP_FREE(temp); temp = NULL; }"
]
_ ->
unlines
[ " temp = " ++ pathToC strFunctionPath ++ "(" ++ prefix ++ "p->" ++ memberName ++ ");",
" sprintf(bufferPtr, \"%s \", temp);",
" snprintf(bufferPtr, size - (bufferPtr - buffer), \"%s \", temp);",
" bufferPtr += strlen(temp) + 1;",
" if(temp) { CARP_FREE(temp); temp = NULL; }"
]
Expand Down
4 changes: 2 additions & 2 deletions src/Sumtypes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -422,11 +422,11 @@ tokensForStr typeEnv env generic concrete fields =
let (name, tys, correctedTagName) = namesFromCase theCase concrete
in unlines
[ " if(p->_tag == " ++ correctedTagName ++ ") {",
" sprintf(bufferPtr, \"(%s \", \"" ++ name ++ "\");",
" snprintf(bufferPtr, size - (bufferPtr - buffer), \"(%s \", \"" ++ name ++ "\");",
" bufferPtr += strlen(\"" ++ name ++ "\") + 2;\n",
joinLines $ memberPrn typeEnv env <$> unionMembers name tys,
" bufferPtr--;",
" sprintf(bufferPtr, \")\");",
" snprintf(bufferPtr, size - (bufferPtr - buffer), \")\");",
" }"
]
calculateStructStrSize :: [TC.TypeField] -> String
Expand Down
2 changes: 1 addition & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# resolver:
# name: custom-snapshot
# location: "./custom-snapshot.yaml"
resolver: lts-19.2
resolver: lts-22.14

# User packages to be built.
# Various formats can be used as shown in the example below.
Expand Down