putchar returns error argument cannot be negative (negative returns) - putchar

int c;
c = getchar();
putchar(c);
I am getting build error in Jenkins
18:55:22 Abc.c:8: CID 42303 (#1 of 1):
18:55:22 Type: Argument cannot be negative (NEGATIVE_RETURNS)
18:55:22 Classification: Unclassified
18:55:22 Severity: Unspecified
18:55:22 Action: Undecided
18:55:22 Owner: Unassigned
18:55:22 Defect only exists locally.
Can someone please explain how do I resolve this error.

Related

Kapacitor alert using derivative value

I am trying to generate alert when the Cisco router's interface throughput exceeds certain value. Please have a look at my code.
I am using telegraph to collect the data. My measurement "monitor usage" contains multiple field keys and values. How to separate them and alert on each of them? Am I using "derivative" node correctly? Is it the field key I should use in the "derivative" node?
Is there a way to log each node output to help troubleshooting? In my case, how do I see "bytes_recv_per_sec" value as being calculated by the "alert" node?
What does "log" node do exactly? Where is the log file? I don't see much valuable information in "/var/log/kapacitor/kapacitor.log"
I have tried playing with different nodes with different parameter methods without much success. Thanks for any help.
dbrp "telegraf"."autogen"
stream
|from()
.measurement('monitor usage')
.where(lambda: "agent_host" == '10.92.192.15')
|window()
.period(1m)
.every(1m)
|httpOut('dump')
|stats(1m)
|httpOut('stats')
|derivative('Envision_Po1.891_ifHCInOctets')
.unit(1s).nonNegative()
.as('bytes_recv_per_sec')
|alert()
.warn(lambda: "bytes_recv_per_sec" > 40.0)
.crit(lambda: "bytes_recv_per_sec" > 80.0)
// post to logfile
.log('/tmp/alerts.log')
At this stage I want to see "/tmp/alerts.log" to generate some alert message when the alert threshold is met. Eventually I want to send an alert email.
As per request, here is info about my database on the "monitor usage" measurement
> show series from "monitor usage";
key
---
monitor\ usage,agent_host=10.85.1.5,host=dzhao-trex,sw_name=it-na-wan-pro-01-11p.int.pason.com
monitor\ usage,agent_host=10.85.1.6,host=dzhao-trex,sw_name=it-na-wan-pro-02-11p.int.pason.com
monitor\ usage,agent_host=10.92.192.15,host=dzhao-trex,rtr_name=irt01-00rm255r2r1.int.pason.com
monitor\ usage,agent_host=10.92.192.17,host=dzhao-trex,sw_name=wsw01-00rm255r2r1.pason.com
monitor\ usage,agent_host=172.19.254.200,host=dzhao-trex,sw_name=ssw01-04rm120r7.int.pason.com
monitor\ usage,agent_host=192.168.195.1,host=dzhao-trex,sw_name=wrt01-06.int.pason.com
> show field keys from "monitor usage";
name: monitor usage
fieldKey fieldType
-------- ---------
Envision_Po1.891_ifHCInOctets integer
Envision_Po1.891_ifHCOutOctets integer
Gi0/0/0_ifHCInOctets integer
Gi0/0/0_ifHCOutOctets integer
GigabitEthernet0/0/0_ifHCInOctets integer
GigabitEthernet0/0/0_ifHCOutOctets integer
GigabitEthernet0/0/2_ifHCInOctets integer
GigabitEthernet0/0/2_ifHCOutOctets integer
HE_Po1.892_ifHCInOctets integer
HE_Po1.892_ifHCOutOctets integer
Po1003_ifHCInOctets integer
Po1003_ifHCOutOctets integer
Rogers_Po1.894_ifHCInOctets integer
Rogers_Po1.894_ifHCOutOctets integer
Shaw_Po1.893_ifHCInOctets integer
Shaw_Po1.893_ifHCOutOctets integer
Te2/5/6_ifHCInOctets integer
Te2/5/6_ifHCOutOctets integer
Tunnel100_ifHCInOctets integer
Tunnel100_ifHCOutOctets integer
Tunnel1_ifHCInOctets integer
Tunnel1_ifHCOutOctets integer
Tunnel2_ifHCInOctets integer
Tunnel2_ifHCOutOctets integer
YYCIX_Gi0/0/1_ifHCInOctets integer
YYCIX_Gi0/0/1_ifHCOutOctets integer
> show tag keys from "monitor usage";
name: monitor usage
tagKey
------
agent_host
host
rtr_name
sw_name

How to allocate a derived type-parameterized (Fortran 2003)?

Am testing the derived type parameterized. the array in the derived type contains a scalar expression .
For example :
integer :: a(n+2)
I used the intel compiler version 18.0 . It works perfectly . But with gfortran 8.3 am having an internal compiler error
For example:
public
type mytab(n)
integer, len :: n
integer :: tab1(n)
integer :: tab2(n*2)
end type mytab
contains
subroutine create(pt1, n)
type(mytab(:)),allocatable, intent(out) :: pt1
integer, intent(in) :: n
allocate (mytab(n)::pt1)
end subroutine
The allocation works only for tab1 and not tab2
this is what a get as an error.
allocate (mytab(n)::pt1)
internal compiler error: in gfc_conv_expr_op, at fortran/trans-expr.c:3498
0x5c5fa9 gfc_conv_expr_op
../../gcc/fortran/trans-expr.c:3498
0x5c5fa9 gfc_conv_expr(gfc_se*, gfc_expr*)
../../gcc/fortran/trans-expr.c:7999
0x704b17 gfc_conv_expr_val(gfc_se*, gfc_expr*)
../../gcc/fortran/trans-expr.c:8056
0x704c30 gfc_conv_expr_type(gfc_se*, gfc_expr*, tree_node*)
../../gcc/fortran/trans-expr.c:8070
0x6e3401 structure_alloc_comps
../../gcc/fortran/trans-array.c:9129
0x6e6260 gfc_allocate_pdt_comp(gfc_symbol*, tree_node*, int, gfc_actual_arglist*)
../../gcc/fortran/trans-array.c:9405
0x73e4cd gfc_trans_allocate(gfc_code*)
../../gcc/fortran/trans-stmt.c:6599
0x6cf5e7 trans_code
../../gcc/fortran/trans.c:2001
0x6f5dbb gfc_generate_function_code(gfc_namespace*)
../../gcc/fortran/trans-decl.c:6515
0x6d2fe9 gfc_generate_module_code(gfc_namespace*)
../../gcc/fortran/trans.c:2227
0x68612b translate_all_program_units
../../gcc/fortran/parse.c:6112
0x68612b gfc_parse_file()
../../gcc/fortran/parse.c:6328
0x6cca5f gfc_be_parse_file
../../gcc/fortran/f95-lang.c:204
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

Haskell *** Exception: Prelude.read: no parse

Hi I am trying to complete CIS194 Spring 13 when I get the error message *** Exception: Prelude.read: no parse on one of my functions. The file that the function is in is called LogAnalysis.hs and the function is parseMessage, but the file also imports from Log.hs. Why am I geting this error message and how can I fix it?
Here is my code:
https://github.com/Adam-Morris/CIS194/tree/master/Homework-2
read is a function with type read :: Read a => String -> a. This means that read takes String as input and returns a value for some type a provided that a implements the Read type class. read has to know what specific type to return, and it can know that in one of two ways: either the type is given to it explicitly (e.g. read "123" :: Int or read "True" :: Bool) or it infers it from the context. In your case, read infers that it must return an Int because LogMessage expects an Int as its second parameter. So in this case the expression read [y] means: take the Char y, convert it into an one-element string, and then try to convert that to an Int, by parsing it. Now if y happens to contain a character that is not a decimal digit, it will fail (by throwing an exception) because it will not know how to covert it into an integer.
Now how can you deal with that issue? You must check that the input to read is ok before calling it. For example, you can check that y is a digit (using the appropriate function):
parseMessage (x:y:z)
| x == 'I' && isDigit y = LogMessage Info (read [y]) (unwords [z])
...
Alternatively, you can use readMaybe from Text.Read that is like read but it does not throw an exception if it fails, instead it returns a nothing value:
parseMessage (x:y:z)
| x == 'I', Just n <- readMaybe [y] = LogMessage Info n (unwords [z])
The problem is your input message format. You're reading a line as a string, then matching on the characters in the string (since a string is type alias for [Char]).
In your sample.log the first line (I 6 Completed armadillo processing) would be passed in as a string to parseMessage, and the parameters will take the following values:
x = 'I'
y = ' ' --single white space character
z = "6 Completed armadillo processing"
read gets the white space character and throws *** Exception: Prelude.read: no parse
In order to get the values, you could do the following:
parseMessage :: String -> LogMessage
parseMessage msg =
case words msg of
"I":y:z -> LogMessage Info (read y :: TimeStamp) (unwords z)
"W":y:z -> undefined
"E":y:z -> undefined
_ -> undefined
This way the first two valid words (MessageType and TimeStamp in this case) can be extracted easily.

How to know an apoc procedure output name

I am using some of the awesome apoc.refactor procedures. I noticed that in the documentation there is no mention of the output variables names that one can use with YIELDS.
I figured out that refactor.mergeNodes outputs node (as the new merged node), but I can't figure out what is the output name of refactor.to or refactor.from. I tried rel and newRel with no success. I am not a java programmer, but inspecting the code (especially RelationshipRefactorResult.java) I thought 'rel' was the one to go.
This is the query I am trying:
MATCH ()-[r]->(), (n)
WHERE id(r) = 16 AND id(n) = 4
CALL apoc.refactor.from(r,n) YIELD rel
RETURN rel
And this is the output message:
Unknown procedure output: `rel` (line 3, column 36 (offset: 96))
"RETURN rel"
Sorry that's a shortcoming of the current docs.
We want to automate / improve that.
You can see the output types if you CALL dbms.procedures()
CALL dbms.procedures() YIELD name, signature
WITH * WHERE name STARTS WITH 'apoc.refactor'
RETURN name, signature
The signature is always name :: TYPE
e.g. in your case:
apoc.refactor.to(relationship :: RELATIONSHIP?, newNode :: NODE?)
:: (input :: INTEGER?, output :: RELATIONSHIP?, error :: STRING?)
Parameters:
Name: relationship, Type: Relationship
Name: newNode, Type: Node
Output Columns:
Name: input, Type: Integer
Name: output, Type Relationship
Name: error, Type: String
Building on the answer of Michael, here is a little tool.
Just a query that builds tidy documentation for these. :)
Maybe it can be adapted to work for others procedures too.
//EXPOSED YIELD PARAMETERS OUTPUT FROM apoc.periodic...
CALL dbms.procedures() YIELD name, signature
WITH * WHERE name STARTS WITH 'apoc.periodic'
RETURN name AS procedure, 'YIELD',
tail(
apoc.text.split(
toString(apoc.text.split(signature, '\\)')[1])
, '[^a-z]+[^a-zA-Z]*[^a-z]')
) AS exposed_parameters

Erlang arithmetic operations on ets:select result

I have an ets table which you can imagine there are two columns, "Key" and Value. Value is an integer.
When I tried:
Ans = ets:select(Table_name, MS),
Ans + 1.
where Ans equals to the expected Value.
I got a error:
** exception error: an error occurred when evaluating an arithmetic expression
Can I not do any arithmetic operation on the ets:select return value?
in the ets module spec: select(Tab, MatchSpec) -> [Match], the reurn value is a list of match. If your match specification define one single integer value as return, you will receive a list of integer. In your case, it seems that this list will always have a length of 1 element, if it must be the case, you can write:
[Ans] = ets:select(Table_name, MS),
Ans + 1.
But beware that this code will crash if the returned list is empty or have more than 1 element.
ets:select(Table_name, MS)
will return result in a List.
So instead, the following would work:
[Ans] = ets:select(Table_name, MS),
Ans + 1.

Resources